温馨提示×

如何查看debian context

小樊
53
2026-10-21 21:05:21
栏目: 智能运维

在 Debian 里,“context” 这个词在不同场景下含义差别很大,先确认你指的是哪一种,我再给对应查看方法。


1. SELinux Context(安全上下文)

Debian 默认不启用 SELinux(通常用 AppArmor),但如果你手动启用了:

# 查看文件 context
ls -Z /path/to/file

# 查看进程 context
ps -Z

# 查看当前模式
sestatus

如果输出里显示 unconfined 或命令不存在,说明没用 SELinux。


2. AppArmor Context(Debian 默认)

Debian 一般用 AppArmor 而不是 SELinux:

# 查看进程是否被 AppArmor 限制
ps auxZ

# 查看 AppArmor 状态
aa-status

3. systemd 的 Context(服务运行环境)

如果你说的是 service 的运行上下文(用户、环境、目录等):

systemctl show nginx.service

只看关键 context 信息:

systemctl show nginx.service | grep -E "User|WorkingDirectory|Environment"

4. Docker / 容器 Context

如果是 Docker:

docker context ls
docker inspect <container_id>

5. 用户 / Shell 环境 Context

whoami
id
pwd
env

6. 文件 ACL / 扩展属性 Context

getfacl /path/to/file
getfattr -d /path/to/file

建议你补充一句:

  • 你是在 排错、做安全加固、写服务、还是用容器?
  • 看到 “context” 这个词是在 哪条命令 / 哪份文档 里?

我可以直接给你最精确的命令。

0 踩