在 CentOS(以及其它使用 SELinux 的 RHEL 系系统)中,你说的 context 文件 通常指以下几类,取决于你具体想找什么:
SELinux 的“文件/目录默认 context”规则主要来自:
/etc/selinux/targeted/contexts/files/file_contexts
这是最重要的 context 文件,记录了系统中大多数路径的默认 SELinux 类型。
相关文件还有:
/etc/selinux/targeted/contexts/files/file_contexts.homedirs
/etc/selinux/targeted/contexts/files/file_contexts.local
file_contexts:系统策略生成file_contexts.local:你用 semanage fcontext 添加的自定义规则如果你用命令添加过:
semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"
规则会保存在:
/etc/selinux/targeted/contexts/files/file_contexts.local
查看自定义规则:
cat /etc/selinux/targeted/contexts/files/file_contexts.local
ps -Z
ls -Z /path/to/file
id -Z
如果你编译过自定义 SELinux 模块:
*.fc 文件 # file context 定义文件
例如:
myapp.fc
编译后会在:
/etc/selinux/targeted/contexts/
/etc/selinux/targeted/contexts/users/
| 目的 | 文件路径 |
|---|---|
| 系统默认 context | /etc/selinux/targeted/contexts/files/file_contexts |
| 自定义 context | /etc/selinux/targeted/contexts/files/file_contexts.local |
| 查看某文件 context | ls -Z |
| 修改 context 规则 | semanage fcontext + restorecon |
如果你能说清楚你是:
我可以直接给你具体命令。