2.3. 将 SELinux 更改为 enforcing 模式
将 SELinux 配置为以 enforcing 模式运行,从而通过拒绝未经授权的访问来保护您的系统。在这个模式中,系统强制执行载入的安全策略并阻止策略违反情况。如果您要从禁用的状态启用 SELinux,则系统会在下次引导时自动重新标记文件。
当您使用 SELinux 安装系统时,RHEL 默认启用 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. SELINUX=enforcing # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted保存更改,重启系统:
# reboot在下一次引导中,SELinux 会重新标记系统中的所有文件和目录,并为禁用 SELinux 时创建的文件和目录添加 SELinux 上下文。
验证
系统重启后,确认
getenforce命令返回Enforcing:$ getenforce Enforcing
故障排除
切换到 enforcing 模式后,SELinux 可能会因为不正确或缺少 SELinux 策略规则而拒绝某些操作。
要查看 SELinux 拒绝的操作,以 root 用户身份输入以下命令:
# ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts today另外,如果安装了
setroubleshoot-server软件包,请输入:# grep "SELinux is preventing" /var/log/messages如果 SELinux 是活跃的,且 Audit 守护进程(
auditd)没有在您的系统中运行,在dmesg命令输出中搜索特定的 SELinux 信息:# dmesg | grep -i -e type=1300 -e type=1400
如需更多信息,请参阅 SELinux 故障排除。