Security Enhanced Linux是一个Linux安全模块,用于强制或基于角色的访问控制。SELinux默认与CentOS和Fedora打包在一起,可以以三种模式之一运行:禁用、允许或强制执行。
理想情况下,您希望将SELinux保持在强制模式,但有时您可能需要将其设置为许可模式,或者完全禁用它。请注意,禁用状态表示守护程序仍在运行,并且仍在执行自主访问控制的规则,但是没有使用MAC安全策略,也没有记录任何违规。
sestatus
查看系统上SELinux的当前强制模式。您可以在下面看到SELinux设置为许可模式。[root@centos ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: permissive
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28
setenforce
更改为强制模式。这仅适用于当前的运行时会话。如果希望设置在重新启动后仍然存在,则需要编辑SELinux配置文件。setenforce 0 # Set to permissive mode.
setenforce 1 # Set to enforcing mode.
setenforce
更改为强制模式,以便重新启动后模式更改依然存在。下面的sed
命令作为示例给出,并将从许可模式切换到强制模式。对于不同的模式配置,只需将命令中的两个单词替换为您当前具有的模式和要启用的模式(例如禁用为允许)。sed -i 's/SELINUX=permissive/SELINUX=enforcing/g' /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=enforcing
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
sestatus
。输出应显示您处于‘使用setenforce
更改为强制模式’步骤和‘使用setenforce
更改为强制模式步骤’中设置的模式。[root@centos ~]# 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
Max kernel policy version: 28
有关此主题的其他信息,您可能需要参考以下资源。虽然提供这些是希望它们有用,但请注意,我们无法保证外部托管材料的准确性或及时性。
更多Linux教程请前往腾讯云+社区学习更多知识。
参考文献:《How to Change SELinux Modes》
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。