6.3. 确保所需的 SELinux 状态

默认情况下,SELinux 在 enforcing 模式下运行。然而,在特定情况下,您可以将 SELinux 设置为 permissive 模式,甚至可以禁用 SELinux。

重要

红帽建议使您的系统保持在 enforcing 模式下。为了进行调试,您可以将 SELinux 设置为 permissive 模式。

按照以下步骤更改系统中 SELinux 的状态和模式。

流程

  1. 显示当前的 SELinux 模式:

    $ getenforce
  2. 临时设置 SELinux:

    1. Enforcing 模式:

      # setenforce Enforcing
    2. Permissive 模式:

      # setenforce Permissive
      注意

      重启后,SELinux 模式被设置为在 /etc/selinux/config 配置文件中指定的值。

  3. 要将 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 模式