Linux管理 SELinux功能

SELinux功能


SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,这个功能管理员又爱又恨,大多数生产环境也是关闭的做法,安全手段使用其他方法。


大多数ssh连接不上虚拟机,都是因为防火墙和selinux阻挡了


永久关闭方式:


1.修改配置文件,永久生效关闭selinux
cp /etc/selinux/config /etc/selinux/config.bak #修改前备份

2.修改方式可以vim编辑,找到
# 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

3.用sed替换
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

4.检查状态
grep "SELINUX=disabled" /etc/selinux/config
#出现结果即表示修改成功


临时关闭selinux(命令行修改,重启失效):


getenforce #获取selinux状态
#修改selinux状态
setenforce
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
数字0 表示permissive,给出警告,不会阻止,等同disabled
数字1表示enforcing,表示开启


Tip:


修改selinux配置后,想要生效还得重启系统,技巧就是(修改配置文件+命令行修改,达到立即生效)

生产环境的服务器是禁止随意重启的!!!!