GNU/Linux >> Linux の 問題 >  >> Linux

RHEL/CentOS で SELinux モードを有効/無効にする方法

SELinux モード

SELinux は、システム内のリソースに追加のセキュリティ レイヤーを提供します。 DAC (任意アクセス制御) とは対照的に、MAC (強制アクセス制御) を提供します。 SELinux モードの設定に入る前に、さまざまな SELinux 操作モードとは何か、およびそれらがどのように機能するかを見てみましょう。 SELinux は 3 つのモードのいずれかで動作できます:

<強い>1.強制 :ポリシーに反するアクションはブロックされ、対応するイベントが監査ログに記録されます。
2.許容 :ポリシーに反するアクションは、監査ログにのみ記録されます。
3.無効 :SELinux は完全に無効になっています。

SELinux モードの一時的な切り替え

SELinux モードを一時的に切り替えるには、以下に示すように setenforce コマンドを使用できます。

# setenforce [ Enforcing | Permissive | 1 | 0 ]

0 –> 許容
1 –> 強制

または、単純に値を疑似ファイルにエコーすることもできます – /sys/fs/selinux/enforce または /selinux/enforce .

# echo [0|1] > /sys/fs/selinux/enforce

SELinux の現在のモードを確認するには:

# getenforce
Enforcing

または、sestatus コマンドを使用して詳細なステータスを取得することもできます:

# sestatus
SELinux status:                 enabled         
SELinuxfs mount:                /selinux        --> virtual FS similar to /proc
Current mode:                   enforcing       --> current mode of operation 
Mode from config file:          permissive      --> mode set in the /etc/sysconfig/selinux file.
Policy version:                 24
Policy from config file:        targeted

SELinux モードの永続的な変更

/etc/sysconfig/selinux ファイルの使用
SELinux モードを永続的に Enforcing または Permissive のいずれかに変更する方法の 1 つは、/etc/sysconfig/selinux ファイルを編集して SELINUX パラメーター値を enforcing または permissive に設定することです。

# ls -l /etc/sysconfig/selinux
lrwxrwxrwx. 1 root root 17 Mar  2 13:03 /etc/sysconfig/selinux -> ../selinux/config
# cat /etc/sysconfig/selinux

# 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

このファイルを編集し、システムを再起動して変更を有効にしてください。

カーネル ブート パラメータの使用
起動時に Kernel 起動パラメータを使用して、SELinux モードを設定することもできます。このために、/etc/grub.conf を編集します ファイルを開き、オプション “selinux=1 enforcing=[0|1]” を追加します

# cat /etc/grub.conf
........
	root (hd0,0)
	kernel /vmlinuz-2.6.32-279.el6.x86_64 root=/dev/md3 selinux=1 enforcing=0
	initrd /initramfs-2.6.32-279.el6.x86_64.img
.........

selinux=1 –> SELinux を有効にします
enforcing=0 –> Permissive モード
enforcing=1 –> Enforcing モード

SELinux を無効にする

SELinux の機能に慣れていない場合は、無効にしたほうがよい場合があります。再起動せずに SELinux を無効にすることはできません。別のオプションは、SELinux を Permissive モードに設定することです。 SELinux を完全に無効にするには、構成ファイル /etc/sysconfig/selinux を編集します。 または /etc/selinux/config これは /etc/sysconfig/selinux ファイルへのソフト リンクです。

# ls -l /etc/sysconfig/selinux
lrwxrwxrwx. 1 root root 17 Mar  2 13:03 /etc/sysconfig/selinux -> ../selinux/config
# cat /etc/sysconfig/selinux

# 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

このファイルを編集し、システムを再起動して変更を有効にしてください。

カーネル ブート パラメータを使用して SELinux を無効にする
SELinux を永続的に無効にするもう 1 つの方法は、カーネル ブート パラメータを編集することです。 /etc/grub.conf ファイルを編集し、selinux=0 オプションを起動オプションに追加して、起動時に SELinux を無効にします。この場合、/etc/sysconfig/selinux の設定は無視されます。

# cat /etc/grub.conf
........
	root (hd0,0)
	kernel /vmlinuz-2.6.32-279.el6.x86_64 root=/dev/md3 selinux=0
	initrd /initramfs-2.6.32-279.el6.x86_64.img
.........


Linux
  1. CentOSでSELinuxを無効にする方法は?

  2. CentOS / RHEL 6,7 :XDMCP サービス (GDM) を有効または無効にする方法

  3. CentOS / RHEL 7 で IPv6 を有効にする方法

  1. CentOS / RHEL 6:IPv6 を無効にする方法

  2. CentOS / RHEL 5、6 :NetworkManager を無効にする方法

  3. CentOS/RHEL 8 で NetworkManager を無効にする方法

  1. CentOS7/6およびRHEL7/6でSELinuxを無効にする方法

  2. CentOS / RHEL 7 :Firewalld を起動 / 停止または有効 / 無効にする方法

  3. CentOS / RHEL 7 で IPv6 を無効にする方法