SELinux的设置及应用举例

SELinux

a.SELinux
SELinux是内核级加强型防火墙,在更改配置文件后必须重启。 主要作用就是最大限度地减小系统中服务进程可访问的资源(最小权限原则)。限制了root用户的最大访问权限。
首先,介绍selinux的三种模式
a.enforcing: linux下SELinux所设置的安全策略都会被启用,所有与SELinux安全策略有关的服务或者程序都会进行权限检查
b.permissive:Linux下SELinux所设置的安全策略都会被启动,但是所有与SELinux安全策略有关的服务或者程序如果违反权限会收到警告,并记录日志。
c.disable:关闭SELinux,

(1),将SELinux设置为enforcing后,将其他文件移入/var/ftp中,此时匿名用户登陆后看不到此文件:
在server虚拟机中:
touch /mnt/westos
mv /mnt/westos /var/ftp
在desktop中:
lftp 172.25.254.100 看不到westos
安全上下文——SELinux的核心:
安全上下文有四个字段,分别用冒号隔开
例:
system_u:object_r:public_cotent_t:s0
用户: 角色: 类型: 级别

ls -Z /var/ftp 查看/var/ftp中的文件安全上下文
ps auxZ | grep vsftpd 查看进程安全上下文
lftp 172.25.254.100 -u student

临时更改SELinux模式
getenforce 查看当前SELinux模式
setenforce 0 更改SELinux模式为pemissive
setenforce 1 更改SELinux模式为
在这里插入图片描述
disabled --> enforcing

touch /mnt/westos1
mv /mnt/westos1 /var/ftp
ls -Z /var/ftp
ps auxZ | grep vsftpd
在这里插入图片描述
setenforce 0 此时设置SELinux为permissive模式
permissive
cat /var/log/audit/audit.log
在这里插入图片描述
##修改安全上下文(临时修改)
chcon -t public_content_t /var/ftp/westos1

#对目录
mkdir /westos
touch /westos/westosfile{1…5}
ls -Zd /westos

vim /etc/vsftpd/vsftpd.conf

anon_root=/westos

lftp 172.25.254.100
setenforce 0 表示关闭selinux防火墙

chcon -t public_content_t /westos -R
ls -Zd /westos
在这里插入图片描述
#把selinux重启一次,安全上下文又变回default_t

修改安全上下文:
semanage fcontext -l | grep /var/ftp
semanage fcontext -l | grep /westos

扫描二维码关注公众号,回复: 4168626 查看本文章

semanage fcontext -a -t public_content_t /westos
semanage fcontext -l | grep /westos ##只改变了westos目录的安全上下文
restorecon -RvvF /westos

semanage fcontext -d -t public_content_t /westos

rm -fr /westos
mkdir /westos
touch /westos/file{1…5}

semanage fcontext -a -t public_content_t ‘/westos(/.*)?’
restorecon -RvvF /westos

getsebool -a | grep ftp 对家目录的控制和链接
ftp_home_dir --> off
在这里插入图片描述
setsebool -p ftp_home_dir on 本地用户可以写,可以删除
seLinux排错
***** Plugin catchall_boolean (57.6 confidence)suggests *************

If you want to allow vsftpd to have getattr access on the file
Then you need to change the label on F I X T A R G E T P A T H D o s e m a n a g e f c o n t e x t a t F I L E T Y P E FIX_TARGET_PATH Do semanage fcontext -a -t FILE_TYPE ' FIX_TARGET_PATH’

Then execute;
restorecon -v ‘$FIX_TARGET_PATH’

***** Plugin catchall_boolean (7.64 confidence)suggests *************

If you believe that vsftpd should be allowed getattr access on the file by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
grep vsftpd /var/log/audit/audit.log | audit2allow -M mypol
semodule -i mypol.pp

rpm -qa | grep setroubleshoot
在这里插入图片描述
setroubleshoot-server-3.2.17-2.e17.x86_64
setroubleshoot-3.2.17-2.e17.x86_64
setroubleshoot-plugins-3.0.59-1.e17.noarch

猜你喜欢

转载自blog.csdn.net/qq_43279936/article/details/83833987
今日推荐