-
查看SELinux状态:
可以看SELinux配置文件:cat /etc/selinux/config 来查看状态
[root@server ~]# 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=disabled # SELINUXTYPE= can take one of three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
也可以用这个命令检查:getenforce
[root@localhost /]# getenforce Enforcing
-
SELinux三个状态的区别:
Disable工作模式(关闭模式)
在 Disable 模式中,SELinux 被关闭,默认的 DAC 访问控制方式被使用。对于那些不需要增强安全性的环境来说,该模式是非常有用的。
Permissive工作模式(宽容模式)
在 Permissive 模式中,SELinux 被启用,但安全策略规则并没有被强制执行。当安全策略规则应该拒绝访问时,访问仍然被允许。然而,此时会向日志文件发送一条消息,表示该访问应该被拒绝。
Enforcing工作模式(强制模式)
从此模式的名称就可以看出,在 Enforcing 模式中, SELinux 被启动,并强制执行所有的安全策略规则。
-
关闭SELinux的方法:
-
临时关闭
#setenforce 0设置为permissive模式;setenforce 1 设置为enforcing模式; setenforce 0
-
永久关闭
要永久禁用SELinux,需要编辑/etc/sysconfig/selinux文件。可以使用文本编辑器(如vim或nano)进行编辑:
- 打开/etc/sysconfig/selinux文件: sudo vi /etc/sysconfig/selinux
- 将SELINUX=enforcing指令更改为SELINUX=disabled
-