查看SELiuxin状态及关闭SELinux

<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,就可以快速关闭了,以及在需要的时候,再开启它.