[root@test ~]# 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 these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
1、狀態解釋
enforcing:強制模式,策略被完整執行,SELinux的主要模式,SELinux 運作中且已經正確的開始限制 domain/type
permissive:寬容模式:SELinux 運作中,策略規則不被強制執行,相反,只是審核遭受拒絕的消息,不過僅會有警告訊息並不會實際限制 domain/type 的存取。這種模式可以運來作為 SELinux 的 debug 之用
disabled:SELinux內核機制是完全關閉的。
2、查看selinux狀態
[root@test ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
[root@test ~]#
3、臨時關閉
setenforce 0
4、臨時打開 permissive轉enforcing
setenforce 1
5、永久改變,需重新開機,整合到內核模塊
cp -a /etc/selinux/config /etc/selinux/config.bak
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
或者 sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
/SELINUX/為包含匹配以//內字符的行
s 替換命令
sed -i 直接修改源文件,沒有-i只是把修改輸出到標准輸出,不修改源文件
s/要查找的字符串/修改后的字符串/
整個命令需要用單引號引起來
最后是要修改的文件名