如果你说的 “CentOS Context” 指的是 SELinux 的安全上下文(Security Context),下面是最常用、最实用的检查方法。
getenforce
Enforcing:启用并强制执行Permissive:仅记录,不拦截Disabled:已关闭查看详细状态:
sestatus
ls -Z /path/to/file
示例:
ls -Z /var/www/html/index.html
输出类似:
unconfined_u:object_r:httpd_sys_content_t:s0 index.html
ls -Zd /var/www/html
ps -eZ
或查看某个进程:
ps -eZ | grep httpd
示例输出:
system_u:system_r:httpd_t:s0 1234 ? 00:00:01 httpd
semanage port -l
查看某个端口:
semanage port -l | grep 80
id -Z
示例:
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
seinfo -t
(需安装 setools-console)
yum install setools-console
chcon -t httpd_sys_content_t /var/www/html/test.html
semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?"
restorecon -Rv /var/www/html
| 类型 | 用途 |
|---|---|
httpd_sys_content_t |
Apache 可访问 |
httpd_sys_rw_content_t |
Apache 可读写 |
ssh_home_t |
SSH 密钥 |
user_home_t |
用户主目录 |
etc_t |
配置文件 |
bin_t |
可执行程序 |
请补充说明,例如:
我可以给你更精确的命令 ✅