SELinux 操作模式:
SELinux 具有三种操作模式。
- Enforcing:这是默认模式。根据 SELinux 策略授予访问权限。
- Permissive:在这种模式下,SELinux 不限制对任何对象的访问。除此之外,它只记录违反 SELinux 政策的行为。此模式适用于调试目的。
- Disabled:既不强制执行 SELinux 策略,也不记录任何消息。
在 CentOS 8 上检查 SELinux 的状态:
默认情况下,所有 CentOS 8 操作系统安装都启用 SELinux。
但它可以由系统管理员明确禁用。
我们可以运行 getenforce 命令来检查 SELinux 的当前模式。
[root@centos-8 ~]# getenforce Enforcing
要查看服务器上 SELinux 的详细状态,我们可以使用以下 Linux 命令。
[root@centos-8 ~]# 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
在 CentOS 8 中临时设置 SELinux 模式:
我们可以暂时(直到下次系统重新启动)在 enforcing 和 permissive 之间切换 SELinux 模式。
Permissive 模式适用于生成 SELinux 安全违规日志以创建自定义 SELinux 策略。
许可模式对于检查 SELinux 是否在强制模式下阻止访问我们的进程或者文件也很有用(例如,我们在自定义端口上配置了 Apache Web 服务器,但它不工作)。
以下 Linux 命令用于将 SELinux 模式更改为 permissive 。
[root@centos-8 ~]# setenforce 0
再次检查 SELinux 的当前模式。
[root@centos-8 ~]# getenforce Permissive
将 SELinux 模式改回执行 .
[root@centos-8 ~]# setenforce 1
什么是 SELinux?
SELinux(Security-Enhanced Linux)是一个 Linux 内核模块,它提供了一种机制来强制执行访问控制安全策略,包括 MAC(强制访问控制)。
SELinux 允许系统管理员根据基于规则的策略控制对操作系统对象的访问,从而为 Linux 服务器增加了另一层安全性。
在 CentOS 8 上永久禁用 SELinux:
在 CentOS 服务器运行时暂时禁用 SELinux 是不可能的。
我们必须通过其配置文件禁用 SELinux,以便下次系统重新启动时 SELinux 将不再启用。
[root@centos-8 ~]# sed -i s/^SELINUX=.*$/SELINUX=disabled/ /etc/selinux/config [root@centos-8 ~]# systemctl reboot
重启后,检查 SELinux 的当前状态。
[root@centos-8 ~]# sestatus SELinux status: disabled
在 CentOS 8 中永久设置 SELinux 模式:
如果我们需要将 SELinux 模式永久设置为 permissive,那么我们也必须在 SELinux 配置文件中设置它。
因此,在下次启动时,SELinux 将以许可模式启动。
[root@centos-8 ~]# sed -i s/^SELINUX=.*$/SELINUX=permissive/ /etc/selinux/config [root@centos-8 ~]# setenforce 0