改为 enforcing 模式 - Amazon Linux 2023
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

改为 enforcing 模式

当您在 enforcing 模式下运行 SELinux 时,SELinux 实用程序就是 enforcing 配置的策略。SELinux 基于策略规则来允许或拒绝访问,以此来控制选定应用程序的功能。

要查找当前 SELinux 模式,请运行 getenforce 命令。

getenforce Permissive

编辑配置文件以启用 enforcing 模式

您可以使用以下步骤将模式改为 enforcing

  1. 编辑 /etc/selinux/config 文件以改为 enforcing 模式。SELINUX 设置应类似以下示例。

    SELINUX=enforcing
  2. 重新启动系统以完成改为 enforcing 模式。

    $ sudo reboot

在下次启动时,SELinux 会重新标记系统中的所有文件和目录。SELinux 还会为在 SELinux 处于 disabled 模式时创建的文件和目录添加 SELinux 上下文。

切换到 enforcing 模式后,由于 SELinux 策略规则不正确或缺失,SELinux 可能会拒绝某些操作。您可以使用以下命令查看 SELinux 拒绝的操作。

$ sudo ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recent

使用 cloud-init 启用 enforcing 模式

或者,当您启动实例时,请将以下 cloud-config 作为用户数据传递以启用 enforcing 模式。

#cloud-config selinux: mode: enforcing

默认情况下,此设置会导致实例重新启动。为了提高稳定性,建议您重启实例。但是,如果您愿意,可以通过提供以下 cloud-config 来跳过重新启动。

#cloud-config selinux: mode: enforcing selinux_no_reboot: 1