Linuxで “ls -l” のパーミッションに現れるドットの謎

Linux で ls -l の表示をした時に、パーミッション欄の右側にドット(“.”)が現れる事がある。

# ll -h /etc/profile.d/
-rw-r--r--. 1 root root 1.2K  4月 28 23:58 2010 colorls.csh
-rw-r--r--. 1 root root 1.2K  4月 28 23:58 2010 colorls.sh
-rw-r--r--  1 root root 1.8K 12月 11 08:19 2011 foo.sh

何度か調べるのだけど、すぐ忘れてしまうのでメモしておく。結論からいうと、パーミッション末尾のドットはSELinuxで使われるセキュリティコンテキストが設定されている事を意味していて、SELinuxを使わないなら気にする必要はない。

$ ll -Z /etc/profile.d/
-rw-r--r--. root root system_u:object_r:bin_t:s0       colorls.csh
-rw-r--r--. root root system_u:object_r:bin_t:s0       colorls.sh
-rw-r--r--  root root ?                                foo.sh

ここで使ったls -Z オプションはSELinuxのセキュリティコンテキストを表示するオプション。

$ ls --help
(抜粋)
SELinux options:

  --lcontext                 Display security context.   Enable -l. Lines
                             will probably be too wide for most displays.
  -Z, --context              Display security context so it fits on most
                             displays.  Displays only mode, user, group,
                             security context and file name.

SELinuxを使わない環境では標準で提供されているファイルについてはコンテキストが設定されているため、このように表示されてしまうようだ。

セキュリティコンテキストを操作するにはsemanageを使う。
参考:SELinux wiki
・追加

# semanage fcontext -a -t [追加するセキュリティコンテキストタイプ] '[適用するファイル/ディレクトリ(正規表現可)]'
# # 実行例
# semanage fcontext -a -t httpd_sys_script_rw_t '/var/www/wiki/(attach|backup|cache|diff|wiki)(/.*)?'

・削除

# semanage fcontext -d -t [削除するセキュリティコンテキストタイプ] '[適用するファイル/ディレクトリ(正規表現可)]'