在 Debian 里,“context” 这个词可能出现在几个不同的场景里,先确认你指的是哪一类,再给对应做法。下面按常见情况分别说明。
Debian 默认 不使用 SELinux,一般用 AppArmor。
如果你手动启用了 SELinux:
ls -Z
ps -Z
chcon -t httpd_sys_content_t /var/www/html/index.html
restorecon -Rv /var/www
semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?"
restorecon -Rv /var/www/html
Debian 更常用 AppArmor 而不是 SELinux。
sudo aa-status
sudo aa-enforce /etc/apparmor.d/usr.sbin.nginx
sudo aa-complain /etc/apparmor.d/usr.sbin.nginx
sudo aa-disable /etc/apparmor.d/usr.sbin.nginx
sudo systemctl reload apparmor
如果你说的是 service 的运行上下文(用户 / 环境 / 权限):
systemctl show nginx | grep -E "User|Environment|WorkingDirectory"
编辑:
sudo systemctl edit nginx
示例:
[Service]
User=www-data
WorkingDirectory=/var/www
Environment=APP_ENV=production
然后:
sudo systemctl daemon-reload
sudo systemctl restart nginx
如果是“用户上下文”:
echo $PATH
echo $LANG
env
管理文件:
/etc/environment~/.bashrc~/.profiledocker context ls
docker context use dev
getfacl /var/www
setfacl -R -m u:deploy:rwx /var/www
我可以给你更精确的操作步骤。