【RHEL9】SELinuxを永続的に無効化する方法

Linux

RHEL9ではRHEL8までとSELinuxを無効化する方法が異なります。この記事ではRHEL9でのSELinuxの無効化方法をまとめました。

この記事ではRHEL9.5を使用してコマンドの実行結果を掲載しています。

2.5. SELinux の無効化 | Red Hat Product Documentation
2.5. SELinux の無効化 | Red Hat Documentation

SELinuxの状態を確認する

以下のコマンドでSELinuxの状態を確認します。rootユーザーでなくとも実行が可能です。

$ getenforce

RHEL9.5のインストール時のSELinuxの状態は以下です。

[root@localhost ~]# getenforce
Enforcing

/etc/selinux/configにSELINUX=disabledを書くのは非推奨

RHEL8までは以下のファイルにSELINUX=disabledと記載することで永続的にSELinuxの無効化が可能でしたが、RHEL9では以下の方法でのSELinuxの無効化は推奨されていません。

/etc/selinux/config
SELINUX=disabled

試しにRHEL9の/etc/selinux/configにSELINUX=disabledを書きOSを再起動してみる

試しにRHEL9で/etc/selinux/configにSELINUX=disabledを記載してOSを再起動してみます。

[root@localhost ~]# cat /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.
# See also:
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/using_selinux/changing-selinux-states-and-modes_using-selinux#changing-selinux-modes-at-boot-time_changing-selinux-states-and-modes
#
# NOTE: Up to RHEL 8 release included, SELINUX=disabled would also
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line. You can use grubby
# to persistently set the bootloader to boot with selinux=0:
#
#    grubby --update-kernel ALL --args selinux=0
#
# To revert back to SELinux enabled:
#
#    grubby --update-kernel ALL --remove-args selinux
#
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

sestatus, getenforceコマンドでSELinuxの状態を確認してみる。

[root@localhost ~]# sestatus
SELinux status:                 disabled
[root@localhost ~]# getenforce
Disabled

これでも無効にはなるようである。

RHEL9ではコマンドでSELinuxを永続的に無効化する

RHEL9では以下のコマンドを実行してOSを再起動することでSElinuxを永続的に無効化します。

# grubby --update-kernel ALL --args selinux=0
# reboot

RHEL9のインストール時デフォルトの/etc/selinux/configの中身

参考までにRHEL9のインストール時のデフォルト/etc/selinux/configファイルをcatコマンドで確認します。

[root@localhost ~]# cat /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.
# See also:
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/                                                                                                                                                             using_selinux/changing-selinux-states-and-modes_using-selinux#changing-selinux-m                                                                                                                                                             odes-at-boot-time_changing-selinux-states-and-modes
#
# NOTE: Up to RHEL 8 release included, SELINUX=disabled would also
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line. You can use grubby
# to persistently set the bootloader to boot with selinux=0:
#
#    grubby --update-kernel ALL --args selinux=0
#
# To revert back to SELinux enabled:
#
#    grubby --update-kernel ALL --remove-args selinux
#
SELINUX=enforcing
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are pro                                                                                                                                                             tected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

タイトルとURLをコピーしました