如何在CentOS 8上禁用SELinux
安全性增强的Linux或SELinux是内置在基于RHEL的发行版使用的Linux内核中的安全机制。
SELinux通过允许管理员和用户基于策略规则控制对对象的访问,为系统增加了一层安全保护。
SELinux策略规则指定进程和用户如何相互交互以及进程和用户如何与文件交互。 如果没有明确允许访问对象的规则(例如,打开文件的进程),则拒绝访问。
SELinux具有三种操作模式:
- 实施:SELinux允许基于SELinux策略规则进行访问。
- 允许的:SELinux仅记录在强制模式下运行将被拒绝的操作。 此模式对于调试和创建新的策略规则很有用。
- 禁用:未加载SELinux策略,并且不记录任何消息。
默认情况下,在CentOS 8中,启用了SELinux并处于强制模式。 强烈建议将SELinux保持为强制模式。 但是,有时它可能会干扰某些应用程序的功能,因此您需要将其设置为许可模式或完全禁用它。
在本教程中,我们将说明在CentOS 8上禁用SELinux。
先决条件
只有root用户或具有sudo特权的用户才能更改SELinux模式。
检查SELinux模式#
使用 sestatus
命令以检查SELinux运行的状态和模式:
sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: actual (secure)
Max kernel policy version: 31
上面的输出显示SELinux已启用并将其设置为强制模式。
将SELinux模式更改为许可#
启用后,SELinux可以处于强制模式或许可模式。 您可以使用以下命令将模式从目标临时更改为许可:
sudo setenforce 0
但是,此更改仅对当前运行时会话有效,并且不会在两次重新引导之间持续存在。
要将SELinux模式永久设置为许可,请执行以下步骤:
打开
/etc/selinux/config
文件并设置SELINUX
修改为permissive
:/ etc / selinux / config
# 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=permissive # SELINUXTYPE= can take one of these three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
保存文件并运行
setenforce 0
命令以更改当前会话的SELinux模式:sudo shutdown -r now
禁用SELinux#
强烈建议不要禁用SELinux,而应将模式更改为宽松模式。 仅在需要使应用程序正常运行时才禁用SELinux。
执行以下步骤永久禁用CentOS 8系统上的SELinux:
打开
/etc/selinux/config
文件并更改SELINUX
重视disabled
:/ etc / selinux / config
# 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=disabled # SELINUXTYPE= can take one of these three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
保存文件并重新启动系统:
sudo shutdown -r now
系统启动后,使用
sestatus
命令以验证SELinux已被禁用:sestatus
输出应如下所示:
SELinux status: disabled
结论#
SELinux是一种通过实施强制访问控制(MAC)来保护系统安全的机制。 SELinux在CentOS 8系统上默认为启用,但是可以通过编辑配置文件并重新引导系统来禁用SELinux。
要了解有关SELinux强大功能的更多信息,请访问CentOS SELinux指南。
如果您有任何疑问或反馈,请在下面发表评论。
安全中心