SELinux工作模式设置(getenforce、setenforce和sestatus令)
12个月前 (04-27)
除了通过配置文件可以对 SELinux 进行工作模式的修改之外,还可以使用令查看和修改 SELinux 工作模式。
除可以查询 SELinux 的运行模式之外,也可以修改 SELinux 的运行模式,即使用 setenforce 令。不过需要注意,setenforce 令只能让 SELinux 在 enforcing 和 permissive 两种模式之间进行切换。如果从启动切换到关闭,或从关闭切换到启动,则只能修改配置文件,setenforce 令就无能为力了。
首先,查看系统当前 SELinux 的工作模式,可以使用 getenforce 令;而如果想要查看配置文件中的当前模式和模式设置,可以使用 sestatus 令,下面的代码显示了这两个令:
[root@localhost ~]# getenforce
#查询SELinux的运行模式
Enforcing
#当前的SELinux是强制模式
[root@localhost ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
除可以查询 SELinux 的运行模式之外,也可以修改 SELinux 的运行模式,即使用 setenforce 令。不过需要注意,setenforce 令只能让 SELinux 在 enforcing 和 permissive 两种模式之间进行切换。如果从启动切换到关闭,或从关闭切换到启动,则只能修改配置文件,setenforce 令就无能为力了。
setenforce 令的基本格式如下:
[root@localhost ~]# setenforce 选项
选项:
0: 切换成 permissive(宽容模式);
1: 切换成 enforcing(强制模式);
例如:
[root@localhost ~]# setenforce 0
#切换成宽容模式
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# setenforce 1
#切换成强制模式
[root@localhost ~]# getenforce
Enforcing