1、临时关闭以及启用
/usr/sbin/setenforce 0 立刻关闭 SELINUX
/usr/sbin/setenforce 1 立刻启用 SELINUX加到系统默认启动里面
echo "/usr/sbin/setenforce 0" >> /etc/rc.local
这样,我们在不需要在CentOS系统中开启SELINUX的时候,就可以快速的去关闭了,以及在需要的时候,在开启它。
2、永久关闭
执行命令
# vi /etc/sysconfig/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=enforcing
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
将红色配置注释掉,并添加一行,操作如下:
1 #SELINUX=enforcing #注释掉
2 #SELINUXTYPE=targeted #注释掉
3 SELINUX=disabled #增加
4 :wq #保存,关闭。
5 shutdown -r now #重启
了解和配置 SELinux
1. 获取当前 SELinux 运行状态
getenforce
可能返回结果有三种 :Enforcing、Permissive 和 Disabled。Disabled
代表 SELinux 被禁用 ,Permissive 代表仅记录安全警告但不阻止可疑行为 ,Enforcing 代表记录警告且阻止可疑行为 。
目前常见发行版中 ,RHEL 和 Fedora 默认设置为 Enforcing, 其余的如 openSUSE 等为 Permissive。
2. 改变 SELinux 运行状态
setenforce [ Enforcing | Permissive | 1 | 0 ]
该命令可以立刻改变 SELinux 运行状态 , 在 Enforcing 和 Permissive 之间切换 , 结果保持至关机 。 一个典型的用途是看看到底是不是 SELinux 导致某个服务或者程序无法运行 。 若是在 setenforce 0 之后服务或者程序依然无法运行 , 那么就可以肯定不是 SELinux 导致的 。
若是想要 永久变更系统 SELinux 运行环境 , 可以通过更改配置文件 /etc/sysconfig/selinux 实现 。
注意当从 Disabled 切换到 Permissive 或者 Enforcing 模式后需要重启计算机并为整个文件系统重新创建安全标签 (touch
/.autorelabel && reboot)。
参考文献:https://linuxtoy.org/archives/selinux-introduction.html
本文介绍如何在CentOS系统中临时及永久地关闭或启用SELinux。包括使用setenforce命令进行临时调整,以及通过编辑配置文件来实现永久性的变化。此外,还提供了获取和更改SELinux运行状态的方法。
5049

被折叠的 条评论
为什么被折叠?



