.
semanage
默认目录的安全性本文查询与修改
你应该要觉得奇怪,为什么
restorecon
可以『恢复』原本的
SELinux type
呢?那肯定就是有个地方
在纪录每个文件
/
目录的
SELinux
默认类型啰?
没错!是这样~那要如何
(1)
查询预设的
SELinux
type
以及
(2)
如何增加
/
修改
/
删除预设的
SELinux type
呢?很简单~透过
semanage
即可!他是这样
使用的:
[root@study ~]#
semanage {login|user|port|interface|fconte
xt|translation}
-
l
[root@study ~]#
semanage fcontext
-
{a|d|m} [
-
frst] file_spec
选项
与
参数
:
fcontext
:主要用在安全性本文方面的用途,
-
l
为
查
询
的意思;
-
a
:增加的意思,你可以增加一些目
录
的默
认
安全性本文
类
型
设
定;
-
m
:修改的意思;
-
d
:
删
除的意思。
范例一:查
询
一下
/etc /etc/cron.d
的
预设
SELinux type
为
何?
[root@study ~]#
semanage
fcontext
-
l | grep
-
E '^/etc |^/etc/cron'
SELinux fcontext type Context
/etc all files system_u:object_r:
etc_t
:s0
/etc/cron
\
.d(/.*). all files system_u:object_r:
system_cron_spool_t
:s0
看到上面输出的最后一行,那也是为啥我们直½使用
vim
去
/etc/cron.d
底下½立新文件时,预设的
SELinux type
就是正确的!
同时,我们也会知道使用
restorecon
回复正确的
SELinux type
时,系
统会去判断默认的类型为何的依据。现在让我们来想一想,
如果
(
当然是假的!不可能这么干
)
我
们要½立一个
/srv/mycron
的目录,这个目录默认也是需要变成
system_cron_spool_t
时,
我们应该
要如何处理呢?基本上可以这样作:
# 1.
先½立
/srv/mycron
同
时
在
内
部放入配置文件,同
时观
察
SELinux type
[root@study ~]#
mkdir /srv/mycron
[root@study ~]#
cp /etc/cron.d/checktime /srv/mycron
[root@study ~]#
ll
-
dZ /srv/mycron /srv/mycron/checktime
drwxr
-
xr
-
x. root root unconfined_u:object_r:
var_t
:s0 /srv/mycron
-
rw
-
r
--
r
--
. root root unconfined_u:object_r:
var_t
:s0 /srv/mycron/checktime
# 2.
观
察一下上
层
/srv
的
SELinux type
[root@study ~]#
semanage fcontext
-
l | grep '^/srv'
SELinux fcontext type Context
/srv all files
system_u:object_r:
var_t
:s0
#
怪不得
mycron
会
是
var_t
啰
!
# 3.
½
mycron
默
认
值改
为
system_cron_spool_t
啰
!
[root@study ~]#
semanage fcontext
-
a
-
t system_cron_spool_t "/srv/mycron(/.*)."
[root@study ~]#
semanage fcontext
-
l | grep '^/srv/mycron'
SELinux fcontext
type Context