1、更改selinux状态
selinux有三种状态
Enforcing ##强制模式 1 ,表示有警告且拒绝访问
Permissive ##警告模式 0 表示有警告但是可以访问
Disabled ##关闭模式
1)开启和关闭
vim /etc/sysconfig/selinux
enforcing
reboot
getenforce
Enforcing
由于selinux是基于内核的,因此修改后需要重启电脑
重启前:
重启后:
2)强制模式和警告模式的更改
setenforce 1 ##修改状态为强制
getenforce
cat /var/log/audit/audit.log ##查看日志文件
实验
touch /mnt/file11
mv /mnt/file11 /var/ftp
ls /var/ftp
setenforce 1 ##修改状态为强制
getenforce
> /var/log/audit/audit.log # #清空日志
lftp访问发现不能看到file11 ##访问
cat /var/log/audit/audit.log ##查看日志,有警告信息
setenforce 0 ##修改状态为警告
getenforce
> /var/log/audit/audit.log ##清空日志 > /var/log/message
lftp访问发现可以看到file11 ##访问
cat /var/log/audit/audit.log ##查看日志,有警告信息
2、修改文件的上下文标识
1)临时修改
chcon -t public_content_t /wang/ -R ##临时修改
实验:
mkdir /wang
ls -Zd /wang/
chcon -t public_content_t /wang/ -R ##临时修改
ls -Zd /wang/
restorecon -FvvR /wang/
ls -Zd /wang/
2)永久修改
semanage fcontext -a -t public_content_t '/westos(/.*)?' ##永久修改 westos(/.*)?表示westos下所有目录文件
semanage fcontext -l |grep westos ##查看上下文标识
restorecon -FvvR /westos/ ##刷新
实验:
mkdir /westos
ls -Zd /westos/
semanage fcontext -a -t public_content_t '/westos(/.*)?' ##永久修改
semanage fcontext -l |grep /westos ##查看上下文标识
ls -Zd /westos/
restorecon -FvvR /westos/ ##刷新
ls -Zd /westos/
3)权限开关
getsebool -a |grep ftp ##查看权限开关状态
setsebool -P ftp_home_dir on ##打开开关,-P表示永久
实验
systemctl start vsftpd
lftp 172.25.254.147 -u student
上传文件,发现无法上传
getsebool -a |grep ftp
setsebool -P ftp_home_dir on
再次上传文件,可以上传