如何在CentOS 7.5上查看、禁用SELinux


SELinux(安全增强型Linux)是一个 Linux 内核安全模块,允许管理员和用户更好地控制访问控制。 它允许基于 SELinux 策略规则进行访问。

SELinux 策略规则指定进程和用户如何相互交互以及进程和用户如何与文件交互。

如果没有专门允许访问的 SELinux 策略规则,例如打开文件的进程,则拒绝访问。

SELinux 有三种模式:

  • 强制执行:SELinux 允许基于 SELinux 策略规则进行访问。
  • 允许:SELinux 仅记录在强制模式下运行时将被拒绝的操作。
  • 已禁用:未加载 SELinux 策略。

默认情况下,在 CentOS 7 中,SELinux 处于启用状态并处于强制执行模式。

在本教程中,我们将向您展示如何在 CentOS 7 系统上禁用查看 SELinux。

建议将 SELinux 保持在强制模式,但在某些情况下,您可能需要将其设置为许可模式,或者完全禁用它。

1、查看
 [linuxidc@localhost www.linuxboy.net]$ getenforce
Enforcing

如何在CentOS 7.5上查看、禁用SELinux

[root@dev-server ~]# /usr/sbin/sestatus -v

如何在CentOS 7.5上查看、禁用SELinux

2、永久关闭
[linuxidc@localhost www.linuxboy.net]$ nano /etc/selinux/config

将SELINUX=enforcing改为SELINUX=disabled
设置后需要重启才能生效

# 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 pr$
#    mls - Multi Level Security protection.
SELINUXTYPE=targeted

如何在CentOS 7.5上查看、禁用SELinux

3、临时关闭
##设置SELinux 成为permissive模式
##setenforce 1 设置SELinux 成为enforcing模式
setenforce 0

4、检查 SELinux 状态

要查看当前SELinux状态以及系统上正在使用的 SELinux 策略,可以使用 sestatus 命令:

[linuxidc@localhost www.linuxboy.net]$ 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:      31

如何在CentOS 7.5上禁用SELinux

您可以从上面的输出中看到 SELinux 已启用并设置为强制模式。

linuxboy的RSS地址:https://www.linuxboy.net/rssFeed.aspx

本文永久更新链接地址:https://www.linuxboy.net/Linux/2018-10/155017.htm

相关内容