selinux对文件的控制
来源:互联网 发布:最小的windows 编辑:程序博客网 时间:2024/06/09 16:49
selinux(安全增强型linux)是可保护系统安全性的额外机制。
在某种程度上,他可以被看作是与标准权限系统并行的权限系统。在常规模式中,以用户身份运行进程,并且系统上的文件和其他资源都设置了权限(控制哪些用户对哪些文件具有访问权)selinux的另外一个不同之处在于,若要访问文件,你必须具有普通访问权限和selinux访问权限。因此,即使以超级用户身份root运行进程,根据进程以及文件或资源的selinux安全性上下文可能拒绝访问文件或资源。
[root@localhost ~]# vim /etc/sysconfig/selinux
[root@localhost ~]# reboot
[root@localhost ~]# getenforce ##显示selinux模式
Enforcing
setenforce0表示permissive ##警告模式
setenforce1表示enforcing ##强制模式
当为enforcing时,不能看到mv的文件
当为permissive时,可以看到mv的文件
在enforcing状态下则可以更改文件标签来看到mv的文件
[root@localhost ~]# chcon -t public_content_t /var/ftp/pub/file ##跟该file的上下文 与本地文件一样
semanage fcotext 永久更改文件上下文
准备:
systemctl status vsftpd ###查看vsftp服务状态
systemctl start vsftpd ###打开服务
systemctl status vsftpd
systemctl status firewalld ####查看状态,打开防火墙
firewall-cmd --list-all ####查看是否通过ftp服务
getenforce ###显示为enforcing模式
[root@localhost ~]# mkdir /westos/ ####创建目录
[root@localhost ~]# ls /westos
file1 file4 westosfile10 westosfile4 westosfile7
file2 file5 westosfile2 westosfile5 westosfile8
file3 westosfile1 westosfile3 westosfile6 westosfile9
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf ####修改匿名用户家目录
[root@localhost ~]# systemctl restart vsftpd ####重启服务
[root@localhost ~]# ps auxZ | grep vsftpd ####查看所有进程,过滤有关vsftpd
[root@localhost ~]# ls -lZ /var/ftp ###显示安全上下文
-rw-r--r--. root root system_u:object_r:public_content_t:s0 file
drwxr-xr-x. root root system_u:object_r:public_content_t:s0 pub
[root@localhost ~]# ls -Zd /westos
drwxr-xr-x. root root system_u:object_r:default_t:s0 /westos
[root@localhost ~]# semanage fcontext -l | grep westos ###显示westos上下文规则
[root@localhost ~]# semanage fcontext -l | grep var/ftp
/var/ftp(/.*)? all files system_u:object_r:public_content_t:s0
/var/ftp/bin(/.*)? all files system_u:object_r:bin_t:s0
/var/ftp/etc(/.*)? all files system_u:object_r:etc_t:s0
/var/ftp/lib(/.*)? all files system_u:object_r:lib_t:s0
/var/ftp/lib/ld[^/]*\.so(\.[^/]*)* regular file system_u:object_r:ld_so_t:s0
[root@localhost ~]# semanage fcontext -a -t public_content_t '/westos(/.*)?' ###修改westos的上下文配置
[root@localhost ~]# semanage fcontext -l | grep var/ftp
/var/ftp(/.*)? all files system_u:object_r:public_content_t:s0
/var/ftp/bin(/.*)? all files system_u:object_r:bin_t:s0
/var/ftp/etc(/.*)? all files system_u:object_r:etc_t:s0
/var/ftp/lib(/.*)? all files system_u:object_r:lib_t:s0
/var/ftp/lib/ld[^/]*\.so(\.[^/]*)* regular file system_u:object_r:ld_so_t:s0
[root@localhost ~]# semanage fcontext -l | grep westos ####查看westos修改后上下文
/westos(/.*)? all files system_u:object_r:public_content_t:s0
[root@localhost ~]# ls -Zd /westos/
drwxr-xr-x. root root system_u:object_r:default_t:s0 /westos/
[root@localhost ~]# restorecon -RvvF /westos/ ####刷新配置
[root@localhost ~]# touch /westos/file ####新建文件,之前修改对所有文件有效
测试:
:
- selinux对文件的控制
- selinux对文件的控制
- selinux对文件的控制
- selinux对文件的控制
- selinux对文件的控制
- selinux对文件的控制
- selinux对文件的控制
- Linux学习第十单元-selinux对文件的控制
- RH134-第二十一节-selinux对文件的控制
- selinux对mysql控制
- Linux运维笔记-文档总结- selinux对文件的控制
- SELinux对网站目录权限控制的不当的问题
- SElinux的强制访问控制
- [顶]解决SELinux对网站目录权限控制的不当的问题 20
- seandroid对selinux的改进
- 控制对文件的访问
- 控制对文件的访问
- 对文件的访问控制
- 基于 Django1.10 文档的深入学习(20)—— Using the Django authentication system 之 login()
- 嵌入式应用编程经验之谈-局部变量造成的死机
- NGINX配置
- 脚本create_swap.sh
- Linux if判断字符串是否相等
- selinux对文件的控制
- 使用PYTHON POPLIB模块实现邮件收取
- iOS学习笔记-- tableView单选的实现
- 忘记密码zabbix
- 小米手机调试总出现“INSTALL_CANCELED_BY_USER”
- 文件描述符fd与文件指针FILE*的关系
- C++外观模式
- 指定eclipse.ini的jdk路径
- Linux设置登录欢迎信息