一、SELinux简介
安全增强型 Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统。主要由美国国家安全局开发。2.6 及以上版本的 Linux 内核都已经集成了 SELinux 模块。
二、selinux的模式
vim /etc/selinux/config ##编辑SELinux 工作模式
1. enforcing:强制模式。违反 SELinux 规则的行为将被阻止并记录到日志中。
2. permissive:宽容模式。违反 SELinux 规则的行为只会记录到日志中。一般为调试用。
3. disabled:关闭 SELinux
重启后生效
用命令修改SELinux的模式(仅限于Enforcing与Permissive之间)
getenforce ##查看当前SELinux的模式
setenforce 0 ##设置当前SELinux的模式为Permissive
setenforce 1 ##设置当前SELinux的模式为Enforcing
三、安全上下文(security context)
ls -Z 文件名 # 查看文件的安全上下文
ps -Z 进程pid # 查看进程的安全上下文
临时修改安全上下文:
(当SELinux的状态从Enforcing 改为Disabled再改回Enforcing 时,临时更改的安全上下文将恢复回去)
环境:
开启ftp服务关闭防火墙
[root@localhost ftp]# getenforce
Enforcing ##当前SELinux的状态为强制模式
[root@localhost ~]# yum install vsftpd lftp -y ##安装vsftpd lftp服务
[root@localhost ~]# systemctl start vsftpd ##开启ftp服务
[root@localhost ~]# systemctl enable vsftpd ##开机自动启动ftp服务
[root@localhost ~]# systemctl stop firewalld ##关闭防火墙
[root@localhost ~]# systemctl disable firewalld
实验:
[root@localhost ~]# touch /mnt/file
[root@localhost ~]# mv /mnt/file /var/ftp/ ##在/var/ftp/以外的目录下建立文件,并移到/var/ftp/目录
[root@localhost ~]# cd /var/ftp
[root@localhost ftp]# ls
pub file
[root@localhost ftp]# touch file1 ##在/var/