SELinux で restorecon してあうあう。

もう、毎回のごとく忘れるので、備忘録。

動かない –> /var/log/audit/audit.log* を見に行く。
毎度のごとく「コンテキストがちげーぜお兄さん」と書かれてる。

そのときに、 chcon で片付けてしまうのが私のひどく悪い癖w

いやね、なんかの拍子に restorecon して、
ぶっ飛ばしてしまうわけですよ。

ということで、それも含めて幅広く、いろいろ備忘録。

 

*ファイル関連。

chcon (CHange file selinux security CONtext)

ファイルとかディレクトリのコンテキストを変える。
一時的にそのファイルに対して、特定のコンテキストを割り当てる時に使うと良さそう

# chcon –t httpd_sys_content_t /home/hogehoge/public_html/ –R

 

ls –aZ

ファイル・ディレクトリに設定されているコンテキストを表示する。
・・要は Z オプションをつける。

# ls –Z
drwxr-xr-x. hogehoge hogehoge unconfined_u:object_r:httpd_user_content_t:s0 public_html

 

restorecon (RESTORE file(s) default selinux security CONtext)

ファイルとかディレクトリのコンテキストをデフォルト設定に戻す。
後述する semanage で恒久的に変更した場合は、その設定に戻る。

(chcon の変更は、restorecon で復元される際に破棄される。)

# restorecon /home/hogehoge/public_html/ –R

 

semanage (SElinux  policy MANAGEment tool)

ファイルとかディレクトリのコンテキストをはじめとする、様々な設定を恒久的に変更する。
このコマンドで変更した内容は、今後もデフォルト設定として保持される。

(ポートに関しては後述)

設定取得 ( –l を使う ) :
# semanage fcontext –l

追加 ( –a を使う ):
# semanage fcontext –a –t httpd_sys_content_t “/home/hogehoge/public_html/(/.*)?”

削除 ( –d を使う ):
# semanage fcontext –d –t httpd_sys_content_t “/home/hogehoge/public_html/(/.*)?”

反映させる ( restorecon を使う ):
# restorecon /home/hogehoge/public_html/ –RF

 

*実行権限関連。

setenforce ( modify the mode selinux is running in. )

Enforcing (制約が施行されてる状態) と Permissive (制約が施行されていない[許可されている] 状態)
の2つを一時的に切り替える。

恒久的に変更する場合は、 /etc/selinux/config の SELINUX を書き換える。

有効にする:
# setenforce 1

無効にする:
# setenforce 0

 

getenforce ( GET the current mode of selinux )

現在、制約が施行されている (Enforcing) か許可されている (Permissive) か、
そもそも動いてないか (Disable) を返す。

# getenforce
Enforcing

 

setsebool (SET SElinux BOOLean value)

ポリシーを変更して、特定の動作を許可したり不許可にしたりという設定ができる。

# setsebool –P ftp_home_dir on

 

getsebool (GET SElinux BOOLean value)

ポリシーを取得したり、全列挙したりする。

全列挙:
# getsebool –a

特定の要素を取得:
# getsebool ftp_home_dir

 

ps –Z

プロセスのドメインを取得する。
・・・要は –Z をつける。

# ps –Z
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 15287 pts/0 00:00:00 bash

 

*通信ポート関連

semanage (SElinux policy MANAGEment tool)

ファイル操作は先述。プロセスが使用するポートなんかもここで設定。

ポートの設定を取得:
# semanage port –l

ポートの設定を追加 ( FTP を 11111 ポートで動作可能にする )
# semanage port –a –t ftp_port_t –p tcp 11111

ポートの設定削除
# semanage port –d –t ftp_port_t –p tcp 11111

 

とりあえず、こんな感じで。であであ。

SELinux で restorecon してあうあう。」への2件のフィードバック

  1. ピンバック: SELinux

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です