Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1543772
  • 博文数量: 1279
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 13084
  • 用 户 组: 普通用户
  • 注册时间: 2018-03-07 16:26
个人简介

Linux学习小标兵,专注Linux资讯分享,技术文章分享

文章分类

全部博文(1279)

文章存档

2023年(236)

2022年(285)

2021年(265)

2020年(248)

2019年(213)

2018年(32)

我的朋友

分类: LINUX

2023-10-11 22:06:05

导读 semanage是用来查询与修改SE默认目录的安全上下文。SELinux的策略与规则管理相关:seinfo命令、sesearch命令、getsebool命令、setsebool命令、semanage命令。下面让我们详细讲解一下chcon命令的使用方法。
语法
semanage {login|user|port|interface|fcontext|translation} -l 
semanage fcontext -{a|d|m} [-frst] file_spec
选项
--l:查询。 
fcontext:主要用在安全上下文方面。 
-a:增加,你可以增加一些目录的默认安全上下文类型设置。 
-m:修改。 
-d:删除。
实例
查询一下/var/www/html的默认安全性本文的设置:
semanage fcontext -l 
SELinux fcontext type Context 
....(前面省略).... /var/www(/.*)? all files system_u:object_r:httpd_sys_content_t:s0 ....(後面省略)....

如上面例子所示,我们可以查询的到每个目录的安全性本文!而目录的设定可以使用正则表达式去指定一个范围。那么如果我们想要增加某些自定义目录的安全性本文呢?举例来说,我想要色设置/srv/samba成为 public_content_t内联代码的类型时,应该如何设置呢?

semanage命令设置/srv/samba目录的默认安全性本文为public_content_t
chcon -t public_content_rw_t /var/ftp/incoming
允许用户HHTP访问其家目录,该设定限仅于用户的家目录主页:
mkdir /srv/samba 
ll -Zd /srv/samba 
drwxr-xr-x root root root:object_r:var_t /srv/samba
如上所示,默认的情况应该是var_t这个咚咚的!
semanage fcontext -l | grep '/srv' 
/srv/.* all files system_u:object_r:var_t:s0 
/srv/([^/]*/)?ftp(/.*)? all files system_u:object_r:public_content_t:s0 
/srv/([^/]*/)?www(/.*)? all files system_u:object_r:httpd_sys_content_t:s0 /srv/([^/]*/)?rsync(/.*)? all files system_u:object_r:public_content_t:s0 /srv/gallery2(/.*)? all files system_u:object_r:httpd_sys_content_t:s0 
/srv directory system_u:object_r:var_t:s0 //看这里!
上面则是默认的/srv底下的安全性本文资料,不过,并没有指定到/srv/samba
semanage fcontext -a -t public_content_t "/srv/samba(/.*)?" 
semanage fcontext -l | grep '/srv/samba' 
/srv/samba(/.*)? all files system_u:object_r:public_content_t:s0
cat /etc/selinux/targeted/contexts/files/file_contexts.local 
# This file is auto-generated by libsemanage # Please use the semanage command to make changes 
/srv/samba(/.*)? system_u:object_r:public_content_t:s0 #写入这个档案
restorecon -Rv /srv/samba* #尝试恢复默认值 ll -Zd /srv/samba drwxr-xr-x root root system_u:object_r:public_content_t /srv/samba/ #有默认值,以后用restorecon命令来修改比较简单!
阅读(104) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~