配置SELinux
我们已经在Selinux的由来和安全上下文中了解到SELinux的基本概念。
我们知道SELinux会对进程和文件进行权限控制,而让阻止某些进程访问不该访问的文件。
实际上,在真实场景中,虽然SELinux为默认的内核模块,然而实际上,我们还是可以控制其开启和执行。
首先,让我们查看默认的当前的SELinux配置:
$ cat /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 three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
则我们可看到默认的政策是targeted,工作模式默认为enforcing,而在该文件中,我们看到工作模式有三种选择:
- enforcing: 强制模式。违反SELinux规则的行为将被阻止并记录到日志中。
- permissive: 宽容模式。违反SELinux规则的行为将会被记录在日志中,但并不会被阻止。
- disabled: 关闭模式。关闭SELinux。不用MAC控制,使用DAC控制。
除了查看配置文件这种永久生效的,我们还可以进行实时查看和更新配置,如:
# 查看当前工作模式
$ getenforce
Enforcing
# 查看setenforce命令
$ setenforce --help
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
# 更改SELinux工作模式为Permissive
$ sudo setenforce 0
$ getenforce
Permissive
# 查看整个SELinux服务