<1>SELinux 模式
并非所有 Linux distributions 都支援 SELinux, 目前 SELinux 支援三种模式, 分别如下:
*enforcing(强制模式), 代表 SELinux 运作中, 且已经正确的开始限制 domain/type 了;
*permissive(宽容模式), 代表 SELinux 运作中, 不过仅会有警告讯息并不会实际限制 domain/type 的存取, 这种模式可以用来作为 SELinux 的 debug 之用;
*disabled(关闭),SELinux 并没有实际运作;
<2>检视 SELinux 模式
命令 : getenforce
[root@sqj ~]# getenforce
Enforcing <==显示当前的模式为 Enforcing
<3>检视 SELinux 的政策 (Policy)
[root@sqj ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux <==SELinux 的相关档案资料挂载点
Current mode: enforcing <==目前的模式
Mode from config file: enforcing <==设定档指定的模式
Policy version: 24
Policy from config file: targeted <==目前的政策
<4>通过配置档案 (/etc/selinux/config) 调整 SELinux 的引数
[root@sqj ~]# vi /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 <==预设政策
注: 无论是启动模式或预设政策修改, 都需要重启才能生效.
<5>检视 SELinux 状态
命令 : /usr/sbin/sestatus -v
[root@sqj ~]# /usr/sbin/sestatus -v
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
<6>关闭 SELinux 的方法
* 修改/etc/selinux/config 档案中的 SELINUX=”” 为 disabled, 然后重启;
*若不想重启系统, 使用命令 setenforce 0
注:
setenforce 1 设定 SELinux 为 enforcing 模式;
setenforce 0 设定 SELinux 为 permissive 模式;
同样, 在 grub 的启动引数中增加 selinux=0 也可以关闭 SELinux.
*快速关闭 SELinux
/usr/sbin/setenforce 0 立刻关闭 SELinux
/usr/sbin/setenforce 1 立刻启用 SELinux
可以加入系统启动里面
echo “/usr/sbin/setenforce 0” >>/etc/rc/local
这样, 我们就不需要再 centos 系统中开启 SELinux, 就可以快速关闭了, 以及在需要的时候, 再开启它.