2.3. 将 SELinux 更改为 enforcing 模式
当 SELinux 处于 enforcing 模式时,它会强制 SELinux 策略并根据 SELinux 策略规则拒绝访问。在 RHEL 中,当系统最初使用 SELinux 安装时,默认启用 enforcing 模式。
先决条件
-
selinux-policy-targeted
、libselinux-utils
和policycoreutils
软件包已安装在您的系统中。 -
未使用
selinux=0
或enforcing=0
内核参数。
流程
在文本编辑器中打开
/etc/selinux/config
文件,并配置SELINUX=enforcing
选项: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. SELINUXTYPE= can take one of these two values: targeted - Targeted processes are protected, mls - Multi Level Security protection.
# 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
Copy to Clipboard Copied! 保存更改,重启系统:
reboot
# reboot
Copy to Clipboard Copied! 在下一次引导中,SELinux 会重新标记系统中的所有文件和目录,并为禁用 SELinux 时创建的文件和目录添加 SELinux 上下文。
验证
系统重启后,确认
getenforce
命令返回Enforcing
:getenforce
$ getenforce Enforcing
Copy to Clipboard Copied!
故障排除
切换到 enforcing 模式后,SELinux 可能会因为不正确或缺少 SELinux 策略规则而拒绝某些操作。
要查看 SELinux 拒绝的操作,以 root 用户身份输入以下命令:
ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts today
# ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts today
Copy to Clipboard Copied! 另外,如果安装了
setroubleshoot-server
软件包,请输入:grep "SELinux is preventing" /var/log/messages
# grep "SELinux is preventing" /var/log/messages
Copy to Clipboard Copied! 如果 SELinux 是活跃的,且 Audit 守护进程(
auditd
)没有在您的系统中运行,在dmesg
命令输出中搜索特定的 SELinux 信息:dmesg | grep -i -e type=1300 -e type=1400
# dmesg | grep -i -e type=1300 -e type=1400
Copy to Clipboard Copied!
如需更多信息,请参阅 SELinux 故障排除。