semanage命令是用来查询与修改SELinux默认目录的安全上下文。SELinux的策略与规则管理相关命令:seinfo命令、sesearch命令、getsebool命令、setsebool命令、semanage命令。
语法格式:semanage [参数]
常用参数:
-l | 查询 | -a | 增加,你可以增加一些目录的默认安全上下文类型设置 | -m | 修改 | -d | 删除 |
参考实例
查询一下/var/www/html的默认安全性本文的设置:
[root@linuxcool ~]# semanage fcontext -l
用semanage命令设置 /srv/samba 目录的默认安全性本文为public_content_t:
[root@linuxcool ~]# mkdir /srv/samba
ll -Zd /srv/samba
drwxr-xr-x root root root:object_r:var_t /srv/samba
如上所示,默认的情况应该是 var_t :
[root@linuxcool ~]# 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:
[root@linuxcool ~]# semanage fcontext -a -t public_content_t "/srv/samba(/.*)?"
[root@linuxcool ~]# semanage fcontext -l | grep '/srv'
/srv/samba(/.*)? all files system_u:object_r:public_content_t:s0
尝试恢复默认值:
[root@linuxcool ~]# restorecon -Rv /srv/samba* |