Show Table of Contents
4.4. SELinux の状態とモードの永続的変更
「SELinux の状態とモード」の説明にあるように、SELinux は有効または無効にすることができます。有効時には、SELinux には enforcing と permissive の 2 つのモードがあります。
SELinux の実行モードをチェックするには、
getenforce または sestatus コマンドを使います。getenforce コマンドは、Enforcing、Permissive、Disabled のいずれかを返します。
sestatus コマンドは、SELinux のステータスと使用されている SELinux ポリシーを返します。
~]$sestatusSELinux status: enabled SELinuxfs mount: /sys/fs/selinux Current mode: enforcing Mode from config file: enforcing Policy version: 24 Policy from config file: targeted
注記
システムが SELinux を permissive モードで実行している場合、ユーザーにはファイルを誤ってラベル付けすることが可能になります。SELinux が無効の間に作成されたファイルにはラベルが付けられません。enforcing モードに変更するとファイルに間違ったラベルが付けられたりラベルが付けられないことになるので、これが問題になります。間違ったラベルが付いたファイルやラベルなしのファイルが問題を起こさないよう、disabled モードから permissive モードや enforcing モードに変更すると、ファイルシステムは自動的に再ラベル付けを実行します。
4.4.1. SELinux の有効化
SELinux を有効にすると、enforcing または permissive のいずれかのモードで実行することができます。以下のセクションでは、これらのモードに永続的に変更する方法を説明します。
4.4.1.1. Enforcing モード
SELinux が enforcing モードで実行されていると、SELinux ポリシーが強制され、SELinux ポリシールールに基づいてアクセスが拒否されます。Red Hat Enterprise Linux では、SELinux がシステムにインストールされると、enforcing モードがデフォルトで有効になります。
SELinux が無効になっている場合は、以下の手順で enforcing モードにすることができます。
手順4.2 Enforcing モードへの変更
この手順では、以下のパッケージがインストールされていることを前提としています。selinux-policy-targeted、selinux-policy、libselinux、libselinux-python、libselinux-utils、policycoreutils、および policycoreutils-python。これらのパッケージがインストールされていることを確認するには、以下のコマンドを実行します。
rpm -q package_name/etc/selinux/configファイルを以下のように編集します。# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=enforcing # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted- システムを再起動します。
~]#
reboot次回起動時に SELinux はシステム内の全ファイルとディレクトリーに再ラベル付けを実行し、SELinux の無効時に作成されたファイルおよびディレクトリーの SELinux コンテキストを追加します。
注記
enforcing モードに変更した後に、SELinux ポリシールールが間違っているまたは存在しないために、SELinux がアクションを拒否する場合があります。SELinux が拒否するアクションを表示するには、root で以下のコマンドを入力します。
~]# ausearch -m AVC,USER_AVC,SELINUX_ERR -ts today
別の方法では、setroubleshoot-server パッケージがインストールされていれば、root で以下のコマンドを入力します。
~]# grep "SELinux is preventing" /var/log/messages
SELinux がアクションを拒否した場合のトラブルシュートについては、「10章トラブルシューティング」を参照してください。
モードの一時的な変更については、「SELinux の状態とモード」で説明しています。
4.4.1.2. Permissive モード
SELinux を permissive モードで実行すると、SELinux ポリシーは強制されません。システムは操作可能なままで、SELinux が拒否する操作はありませんが、AVC メッセージのみがログ記録されます。これはトラブルシュートやデバッグ、SELinux ポリシーの改善に使用できます。このケースでは、各 AVC がログ記録されるのは 1 回のみです。
永続的に permissive モードに変更するには、以下の手順に従います。
手順4.3 Permissive モードへの変更
/etc/selinux/configファイルを以下のように編集します。# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=permissive # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted- システムを再起動します。
~]#
reboot
モードの一時的な変更については、「SELinux の状態とモード」で説明しています。
4.4.2. SELinux の無効化
SELinux を無効にすると、SELinux ポリシーはまったく読み込まれないので強制されることもなく、AVC メッセージもログ記録されません。このため、「SELinux の利点」に記載されている SELinux の利点も得られません。
重要
Red Hat では、SELinux を永続的に無効にするのではなく、permissive モードで使用することを強く推奨しています。permissive モードの詳細については、「Permissive モード」を参照してください。
SELinux を永続的に無効にするには、以下の手順に従います。
手順4.4 SELinux の無効化
/etc/selinux/configファイル内でSELINUX=disabledと設定します。# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted- システムを再起動して、
getenforceコマンドがDisabledを返すことを確認します。~]$getenforceDisabled

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.