### 一.Selinux的功能 ###
观察现象
①当Selinux未开启时
在/mnt中建立文件被移动到/var/ftp下可以被vsftpd服务访问
匿名用户可以通过设置后上传文件
当使用ls -Z /var/ftp查看文件时显示"?"
ps auxZ | grep vsftpd 时显示: - root 8546 0.0 0.0 26952 408 ? Ss 10:35 0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
②当selinux开启: 在/mnt中建立文件被移动到/var/ftp下不可以被vsftpd服务访问
匿名用户通过设置后仍然不能上传文件
当使用ls -Z /var/ftp查看文件时显示信息
ps auxZ | grep vsftpd 时显示:
system_u:system_r:ftpd_t:s0-s0:c0.c1023 root 6577 0.0 0.0 26952 412 ? Ss 10:50
0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
selinux:①对于文件的影响: 当selinux开启时,内核会对每个文件及每个开启的程序进行标签加载
标签内记录程序和文件的安全上下文(context)
②对于程序功能的影响: 当selinux开启会对程序的功能加载开关,并设定此开关的状态为关闭
当需要此功能时需要手动开启功能开关
此开关叫做sebool
### 二.Selinux的状态及管理 ###
selinux的开启
vim /etc/selinux/config
7 SELINUX=disabled #selinux关闭
7 SELINUX=enforcing #selinux开机设定为强制状态此状态为selinux开启
7 SELINUX=permissive #selinux开机设定为警告状态此状态为selinux开启
"selinux开启或关闭需要重启系统"
enforcing:
不符合条件一定不能被允许,并会收到警告信息
permissive:
不符合条件被允许,并会收到警告信息


selinux状态的查看:
getenforce
selinux开启后强制和警告级别的转换
setenforce 0 ##警告
setenforce 1 ##强制
selinux日志位置: /var/log/audit/audit.log






### 三.Selinux的安全上下文 ###
(1)查看
查看
ls -Z ##查看文件的安全上下文
ls -Zd ##查看目录的安全上下文
ps axZ ##查看进程的安全上下文

(2)修改安全上下文
#临时修改
#此方式更改的安全上下文在selinux重启后会还原
chcon -t 标签 文件|目录
chcon -t public_content_t /var/ftp/westosfile1
chcon -Rt public_content_t /westosdir #修改目录及目录中的所有子文件的安全上下文
#永久修改安全上下文
#如果需要特殊指定安全上下文需要修改内核安全上下文列表
semanage fcontext -l ##查看内核安全上下文列表
semanage fcontext -a -t public_content_t '/westosdir(/.*)?'
restorecon -RvvF /westosdir/
touch /.autorelabel ##重启系统时selinux初始化文件标签开关文件




### 四.SEBOOL ###
getsebool -a ##现实服务的bool值
setsebool -P ftpd_anon_write on #更改

### 五.SEPORT ###
semanage port -l | grep ssh
semanage port -a -t ssh_port_t -p tcp 1111


### 六.setrouble ###
#/var/log/audit/audit.log ##selinux警告信息
#/var/log/messages ##selinux问题解决方案
#setroubleshoot-server ##此软件功能是采集警告信息并分析得到解决方案存放到message中
> /var/log/audit/audit.log
>/var/log/messages





