SELinux一共有3種狀態,分別是Enforcing,Permissive和Disabled狀態。
Enforcing:強制模式。代表SELinux在運行中,且已經開始限制domain/type之間的驗證關系
Permissive:寬容模式。代表SELinux在運行中,不過不會限制domain/type之間的驗證關系,即使驗證不正確,進程仍可以對文件進行操作。不過如果驗證不正確會發出警告
Disabled:關閉模式。SELinux並沒有實際運行
可以通過setenforce命令來設置前面兩種狀態,而如果想修改為disable狀態,需要修改配置文件,同時重啟系統。
Enforcing狀態的值是1,permissive狀態是0,因此設置為permissive,命令就是:setenforce 0|1
臨時關閉SELinux:setenforce 0
臨時開啟SELinux:setenforce 1
查看當前狀態命令:getenforce
1 [root@localhost ~]# setenforce 0 2 [root@localhost ~]# getenforce 3 Permissive
永久關閉SELinux需修改配置文件:cat /etc/selinux/config,修改 SELINUX=disabled。
1 [root@localhost ~]# cat /etc/selinux/config 2 3 # This file controls the state of SELinux on the system. 4 # SELINUX= can take one of these three values: 5 # enforcing - SELinux security policy is enforced. 6 # permissive - SELinux prints warnings instead of enforcing. 7 # disabled - No SELinux policy is loaded. 8 SELINUX=disabled #修改為disabled 9 # SELINUXTYPE= can take one of three two values: 10 # targeted - Targeted processes are protected, 11 # minimum - Modification of targeted policy. Only selected processes are protected. 12 # mls - Multi Level Security protection. 13 SELINUXTYPE=targeted
注意:修改SELinux永久關閉,必須重啟服務器,才能生效。
永久關閉后,不能通過 setenforce 1 命令臨時打開了