よろづやアンテナ

ITから生活の参考になる情報を備忘録代わりに残していきます

CentOS7.7 Selinuxを無効化にする手順

CentOSLinuxでシステム導入時に邪魔をすることが多いので、基本的に無効にすることが多いSelinuxの無効化手順です。セキュリティ要件が厳しいところ以外では無効にして構築することが多いですね。


まずはデフォルトの状態を確認するコマンドが「getenforce」です。

[root@localhost ~]# getenforce
Enforcing


デフォルトでは有効「Enforcing」になっています。ちなみに、確認した結果は、CentOS7.5です。これ以前も基本は同じ結果になったと思います。


続いて、設定変更は以下のファイルに行います。

 

[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.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

 

SELINUX=enforcing」の部分を「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 three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

 

設定を反映させるにはOSの再起動が必要です。OS起動後に「getenforce」で値が「Disabled」になっていればOKです。

 

[root@localhost ~]# getenforce
Disabled

 

また、「permissive」という値を指定することもでき、SELinuxは有効ですが、アクセス制限は行わず警告を出力するという状態にもできますが、まぁ、利用することは少ないですかね。


合わせて、「setenforce」で一時的に有効、無効にすることもありますが、これもあんまり利用しないですかね。