>配置机器时用到的,记录一下。
## 一、简介
SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux 历史上最杰出的新安全子系统。但是一般都不用它,因为它管的东西太多了,想做安全可以用防火墙等其他措施。
## 二、设置
通过查看配置文件的命令 `cat /etc/selinux/config` 来查看状态。

>我的这台机器已经设置为 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=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
```
可以看到 SELinux 共有3个状态enforcing (执行中)、permissive (不执行但产生警告)、disabled(关闭)。
通过修改配置文件来修改 SELinux 的状态
执行 `sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux
/config`
`cat /etc/selinux/config`
最后重启服务器,SELinux状态由 enforcing 变为 disabled 。
当然,一般 Linux 都不能重启,可以使用这个命令 `setenforce 1` 临时(重启即失效)设置 SELinux 成为 enforcing 模式(setenforce 0 设置 SELinux 成为 permissive 模式),用 getenforce 这个命令来检查。
使用 `/usr/sbin/sestatus` 命令来查看 SELinux 的状态。

-77a9eaa487c0424ebd7d355c2a0d4ab4.jpg)
SELINUX设置