SElinux

SElinux是一个linux安全增强功能,其允许用户和管理员对访问控制有更多的控制权。
访问控制可以做到哪个用户可能访问哪些资源的级别。这些资源可以来自文件。标准的Linux存取控制,如文件权限(-rwxr-xr-x)由用户或用户运行的程序修改。相反的,SELinux 的存取权限由系统加载时的policy确定,这个policy不能随意更改。
SELinux同样提供了细粒度的存取控制,不仅仅是对文件的读写执行权限,还可以指定指定谁可以unlink,仅仅append以及移动文件等操作。SELinux同样可以指定除了文件意外的访问权限,如网络资源和进程间通信等。
SELinux是linux上的MAC(mandatory access control)强制访问控制。

selinux 安全模块

永久设定:
[root@desktop4 ~]# vim /etc/sysconfig/selinux //修改配置文件

三种状态:
 enforcing - SELinux security policy is enforced. 
 permissive - SELinux prints warnings instead of enforcing.
 disabled - No SELinux policy is loaded.

SELINUX开启状态:
这里写图片描述
临时设定 (0/1):

[root@desktop4 ~]# setenforce 0 
[root@desktop4 ~]# getenforce //查看
Permissive

实验(selinux开启的情况下):
在桌面创建一个文件hello.html,输入hello

[root@desktop4 html]# cd
[root@desktop4 ~]# cd ~/Desktop/
[root@desktop4 Desktop]# echo hello >hello.html
[root@desktop4 Desktop]# ls
hello.html
这里写图片描述
在/var/www/html下创建文件

[root@desktop4 Desktop]# cd /var/www/html/
[root@desktop4 html]# ls
ks.cfg  rhel7
[root@desktop4 html]# echo "<h1>westos<h1>" > westos.html
[root@desktop4 html]# ls
ks.cfg  rhel7  westos.html

这里写图片描述
将桌面的hello文件mv到/var/www/html/下
在selinux开启的情况下用浏览器打开两个文件hello和westos
用浏览器查看
hello.html报错
这里写图片描述
而westos.html可以看到内容!
这里写图片描述

原因:selinux对于文件有着严格的控制,每一个文件创建时会生成一个标签,也叫做安全上下文,mv不能改变这个文件的安全上下文。
下面我们来看一下这两个文件的安全上下文。

[root@desktop4 html]# ls -Z /var/www/html/
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 hello.html
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 ks.cfg
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 westos.html

这里写图片描述
可以看到上下文是不一样的
我们通过把hello.html的安全上下文改成和westos.html一样的就可以了

[root@desktop4 html]# chcon -t httpd_sys_content_t hello.html
[root@desktop4 html]# ls -Z /var/www/html/
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 hello.html
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 ks.cfg
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 westos.html

这里写图片描述
用浏览器打开hello.html就可以查看到拉!

restorecon 刷新后还原原来文件的上下文
永久修改文件的上下文的话需要一条其他的命令 semanage fcontext

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值