linux基础之selinux

Selinux
SELINUX(安全增强型 Linux)是可保护你系统安性的额外机制•在某种程度上 , 它可以被看作是与标准权限系统并行的权限系统。在常规模式中,以用户身份运行进程 ,并且系统上的文件和其他资源都设置了权限(控制哪些用户对哪些文件具有哪些访问权SELINUX的另一个不同之处在于,若要访问文件,你必须具有普通访问权限和 SELINUX 访问权限。因此,即使以超级用户身份 root 运行进程,根据进程以及文件或资源的SELinux安全性上下文可能拒绝访问文件或资源限)标签

[[email protected] ~]# mkdir /redhat
[[email protected] ~]# ls /redhat

[[email protected] ~]# vim /etc/vsftpd/vsftpd.conf 

[[email protected] ~]# systemctl restart vsftpd

###设置配置文件并重启

linux基础之selinux

[[email protected] ~]# touch/redhat/file{1..10}
[[email protected] ~]# ls  /redhat/
file1  file10  file2  file3  file4  file5  file6  file7  file8  file9

#####在没有改变安全上下文时匿名登陆后看不到文件

linux基础之selinux
[[email protected] ~]# ls -lZ /redhat/

###查看/westos的安全上下文

linux基础之selinux

linux基础之selinux
[[email protected] ~]# semanage fcontext -l | grep redhat
###semanage fcontext 可用与显示或修改 restorrecon 用来设置默认文件上下文的规则并过滤文件的上下文

[[email protected] ~]# ls -lZ /var/ftp/pub/

##chcon -t       一次性定制安全上下文,执行 restorecon 刷新后还原
### semanage fcontext  – 永久更改文件的上下文
[[email protected] ~]#  semanage fcontext -a -t public_content_t  '/redhat(/.*)?'
#####  -a 是添加  -t 是类型  
#####更改文件的安全上下文
 semanagefcontext 使用扩展正则表达式来指定路径和文件名。 fcontext 规则中最常用的扩展正则表达式是(/.*)?, 表示随意地匹配 / 后跟任何数量的字符• semanage fcontext 将递归地与在表达式前面列出的目录
以及该目录中的所有内容相匹配
[[email protected] ~]# ls -lZ /redhat/
##文件的上下文并不会马上改变
linux基础之selinux
[[email protected] ~]# restorecon -RvvF /redhat/

###刷新,

linux基础之selinux
[[email protected] ~]# ls -lZ /redhat/
####安全上下文已改登陆时会显示
linux基础之selinux

###########################################################################################################

#####在selinux开启的情况本地用户的登陆的设置

#####在没有设置时selinux开启的情况下用户无法登陆
linux基础之selinux
[[email protected] ~]# getsebool -a | grep ftp
###查看ftp的selinux策略

####getsebool 用于显示布尔值 , setsebool 用于修改布尔值

[[email protected] ~]# setsebool -P  ftp_home_dir 1
#### -P 是允许
[[email protected] ~]# getsebool -a | grep ftp

linux基础之selinux
[[email protected] ~]# ls -ld /home/student/
dr-x------. 4 student student 4096 Apr 23 02:06 /home/student/

[[email protected] ~]# chmod +w /home/student/

linux基础之selinux

###改变家目录的权限

#######550   权限过大
#######553   权限太小 本身有这个服务
#######530   密码错了
必须安装 setroubleshoot-server 软件包 , 才能将SELinux 消息发送至 /var/log/messages•
etroubleshoot-server 侦听
/var/log/audit/audit.log 中的审核信息并将简短摘要发送至 /var/log/messages

linux基础之selinux

####在设置后用户可以登录

linux基础之selinux