在 CentOS(以及一般的 Red Hat 系 Linux)里,“context” 通常有两种常见含义,需要分情况处理:
getenforce
Enforcing:开启并强制执行Permissive:只记录不阻止Disabled:已禁用setenforce 0
仅当前生效,重启后恢复
编辑配置文件:
vi /etc/selinux/config
修改为:
SELINUX=disabled
然后重启系统:
reboot
✅ 禁用后,SELinux context 将不再生效
SecurityContext(容器 / service)在 service 文件中:
[Service]
SELinuxContext=unconfined_u:unconfined_r:unconfined_t:s0
或
SELinuxContext=
然后:
systemctl daemon-reload
systemctl restart xxx
restorecon -n /path
setfiles -c /etc/selinux/targeted/contexts/files/file_contexts / 2>/dev/null
请补充说明,例如:
我可以给你更精确的命令。
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
reboot
如果你能说明 “centos context”具体出现在哪里(报错 / 命令 / 配置文件),我可以给你更精准的方案。