在 Debian 系统中,“context” 的具体含义取决于你所指的场景。以下是几种常见情况的配置方法:
Debian 默认使用 AppArmor,而非 SELinux。若需配置 SELinux:
sudo apt install selinux-basics selinux-policy-default auditd
sudo selinux-activate
/etc/selinux/config:SELINUX=enforcing # 或 permissive
SELINUXTYPE=default
ls -Z /path/to/file # 查看上下文
chcon -t httpd_sys_content_t /var/www/html/index.html # 临时修改
semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?" # 永久修改
restorecon -Rv /var/www/html # 应用策略
AppArmor 通过配置文件限制程序访问:
sudo aa-status
/etc/apparmor.d/。/etc/apparmor.d/usr.sbin.nginx:/var/www/html/ r,
/var/www/html/** r,
sudo systemctl reload apparmor
配置 systemd 服务的运行环境:
sudo systemctl edit service_name
[Service]
User=www-data
Environment="VAR=value"
sudo systemctl daemon-reload
sudo systemctl restart service_name
配置用户或进程的环境变量、资源限制等:
~/.bashrc 或 ~/.profile 添加环境变量。/etc/security/limits.conf:* soft nofile 65536
* hard nofile 65536
配置网络隔离:
sudo ip netns add myns # 创建命名空间
sudo ip netns exec myns ip addr show # 在命名空间中执行命令
扩展文件权限:
setfacl -m u:username:rwx /path/to/file # 设置 ACL
getfacl /path/to/file # 查看 ACL
请根据具体需求选择对应方法。如需进一步细节,请说明具体场景(如“配置 Nginx 的 SELinux 上下文”)。