📜  如何在不同模式下启用或禁用 SELinux?

📅  最后修改于: 2021-10-28 02:18:52             🧑  作者: Mango

SELinux 代表安全增强型 Linux。 SELinux 就像 Windows 防火墙,但它更安全和私密。它管理所有访问控制策略。我们可以通过使用一些直接命令或实际进入 SELinux 配置文件并编辑状态来控制 SELinux 安全的状态。 SELinux 可以有三个值,enforcing、permissive 和 disabled。强制执行意味着强制执行 SELinux 安全策略。 Permissive 意味着 SELinux 不强制执行,但会打印警告。禁用意味着它不强制执行,也不打印警告。

检查状态

当 SELinux 强制执行时:

# getenforce
如何在不同模式下启用或禁用 SELinux

强制执行

当 SELinux 允许时:

# getenforce
如何在不同模式下启用或禁用 SELinux

宽容的

启用或禁用 SELinux 的两种方法:

  • 通过命令。
  • 编辑 SELinux 配置文件。

通过命令:

#setenforce Enforcing
#getenforce
如何在不同模式下启用或禁用 SELinux

强制执行

#setenforce Permissive
#getenforce
如何在不同模式下启用或禁用 SELinux

强制许可

除了 Enforcing 和 Permissive,您还可以分别使用 1 和 0。例如

#setenforce 0
#getenforce
如何在不同模式下启用或禁用 SELinux

设置强制 0

编辑 SELinux 配置文件:

在 vi 编辑器中打开 SELinux 配置文件。它位于 /etc/selinux/config

#vi /etc/selinux/config
如何在不同模式下启用或禁用 SELinux

配置文件

现在编辑状态为禁用

# 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

~                                                                                
~                                                                                
~                                                                                
~                                                                                
~                                                                                
~                                                                                
~                                                                                
~                                                                                
"/etc/selinux/config" 14L, 548C

现在按 ESC 并输入 :wq 并按 Enter 保存它。现在使用 getenforce 命令检查 SELinux 的状态。

# getenforce
如何在不同模式下启用或禁用 SELinux

禁用 selinux

注意:您需要重新启动系统才能实际看到发生的更改。因此,我们通过编辑配置文件禁用了 SELinux 服务。