温馨提示×

什么命令查centos context

小樊
45
2026-09-03 02:40:23
栏目: 智能运维

在 CentOS 中,“context” 最常见的含义是 SELinux 安全上下文(security context)。下面按常见场景给你命令:


1. 查看文件/目录的 SELinux context

ls -Z /path/to/file

或

ls -Zd /path/to/dir

示例:

ls -Z /var/www/html

2. 查看进程的 SELinux context

ps -eZ

或指定进程:

ps -eZ | grep httpd

3. 查看当前用户 / shell 的 SELinux context

id -Z

4. 查看端口的 SELinux context

semanage port -l

5. 查看某个文件的详细 context(含默认规则)

matchpathcon /path/to/file

6. 如果是 Docker / container context

如果你说的是 容器 context:

docker inspect --format='{{.SecurityOpt}}' 容器名

或

kubectl get pod -o yaml

7. 如果是 systemd / SELinux 策略上下文

semanage fcontext -l

如果你说的 “context” 不是 SELinux,而是:

  • 网络 namespace
  • kubernetes context
  • shell 环境上下文

可以告诉我具体场景,我给你更精确的命令。

0 踩