selinux:影响程序的访问文件,影响程序的服务程序功能,影响服务所使用的资源。
selinux影响程序的访问文件是通过安全上下文来控制的,影响服务程序的功能是通过sebool值来控制的。selinux开启后会关闭系统认为所有不安全的功能,组织所有认为不不安全的操作
1. 安全上下文:
当安全上下文匹配时访问允许,若不匹配时则不被允许;特定的文件被特定的程序访问(例如:ftpd_t 只能访问public_content_t的文件)
移动:不改变文件的属性和权限,重命名的过程;复制:改变文件的属性,新建的过程
touch /mnt/westos 创建文件
mv /mnt/westos /var/ftp 移动到/var/ftp
ls -Z 查看上下文
semanage fcontext -l | grep /var/ftp 查看安全上下文
chcon -t public_content_t westos2 更改安全上下文的类型
2.更改匿名用户家目录后的安全上下文的永久更改:
mkdir /westos
touch /westos/westosfile
vim /etc/vsftpd/vsftpd.conf
anon_root=/westos
systemctl restart vsftpd
lftp 172.25.254.107 不能查看家目录文件
setenforce 0 将selinux设置为警告
lftp 172.25.254.107 可以查看,但有警告
chcon -t public_content_t /westos -R 更改安全上下文类型(临时的,selinux重启后恢复初始)
ls -Z /westos/
重启selinux
vim /etc/sysconfig/selinux
disabled
reboot
vim /etc/sysconfig/selinux
encoforcing
reboot
systemctl stop firewalld 关闭火墙
systemctl disable firewalld
systemctl start vsftpd 开启vsftpd
systemctl enable vsftpd
ls -Z /westos
semanage fcontext -a -t public_context_t /westos(/.*)?永久更改安全上下文类型‘westos(/.*)?==/westos/*/*……目录及所有文件
semange fcontext -l | grep /westos 查看
restorecon -FvvR /westos 刷新
lftp 172.25.254.107 验证 可以查看
服务的
3.sebool值对服务程序功能的影响:
setsebool -P ftp_home_dir on 打开服务开关(-P 永久,为了使系统更安全)
lftp 172.25.254.107 -u student
put /etc/passwd 上传失败
setsebool -a | grep ftp
setsebool -P ftp_home_dir on
lftp 172.25.254.107 -u student 上传成功
4.selinux排错:
实验之前将匿名用户的家目录改为默认位置/var/ftp
touch /mnt/westos
mv /mnt/westos /var/ftp
> /var/log/messages
> /var/log/audit/audit.log
浏览器:ftp://172.25.254.107
cat /var/log/audit/audit.log
cat /var/log/messages
restorecon -v /var/ftp/*
刷新浏览器
yum remove setroubleshoot-server
cat /var/log/messages 没有分析日志的结果
setroubleshoot-server 是分析日志返回解决方案到/var/log/messages中。
5.自定义设置服务端口(selinux影响服务的使用资源):
vim /etc/httpd/conf/httpd.conf
42 Listen 6666 设置默认端口为6666
systemctl restart httpd
setenforce 0
systemctl restart httpd
semanage port -l | grep http查看http服务的端口
semanage port -a -t http_port_t -p tcp 6666 将端口6666加入http端口列表中
semanage port -l | grep http
setenforce 1
systemctl restart httpd(若不能重启,则证明selinux出错,解决:执行touch /.autorelabel;reboot)