6.3. 确保所需的 SELinux 状态
默认情况下,SELinux 在 enforcing 模式下运行。然而,在特定情况下,您可以将 SELinux 设置为 permissive 模式,甚至可以禁用 SELinux。
重要
红帽建议使您的系统保持在 enforcing 模式下。为了进行调试,您可以将 SELinux 设置为 permissive 模式。
按照以下步骤更改系统中 SELinux 的状态和模式。
流程
显示当前的 SELinux 模式:
$ getenforce
临时设置 SELinux:
Enforcing 模式:
# setenforce Enforcing
Permissive 模式:
# setenforce Permissive
注意重启后,SELinux 模式被设置为在
/etc/selinux/config
配置文件中指定的值。
要将 SELinux 模式设定为在重启后会被保留,修改
/etc/selinux/config
配置文件中的SELINUX
变量。例如: 将 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 ...
警告禁用 SELinux 会降低您的系统安全性。避免在
/etc/selinux/config
文件中使用SELINUX=disabled
选项禁用 SELinux,因为这会导致内存泄漏和引发内核 panic 的竞争条件。相反,通过在内核命令行中添加selinux=0
参数来禁用 SELinux。如需更多信息,请参阅 在引导时更改 SELinux 模式。
其他资源