Debian 上下文中的用户权限管理指南
一 概念与目标
二 身份与权限基础
sudo adduser alicesudo usermod -aG sudo alicesudo groupadd devs、sudo usermod -aG devs alicechmod 750 /opt/app、chown alice:devs /opt/appsetfacl -d -m g:devs:rwx /opt/appsudo sed -i 's/^#*PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_configPubkeyAuthentication yes、PermitEmptyPasswords no,重启 sshd 生效sudo ufw allow 22,80,443/tcp && sudo ufw enable三 SELinux 上下文管理
sestatussudo setenforce 1(重启后失效,需写入配置持久化)ls -Z /var/www/html/index.htmlsudo chcon -t httpd_sys_content_t /var/www/html/index.htmlsudo apt install policycoreutils-python-utilssudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?"sudo restorecon -Rv /var/www/htmlsudo ausearch -m avc -ts recent | audit2allow -M myhttpsudo semodule -i myhttp.ppchcon 变更在重标记或 restorecon 后可能丢失;需使用 semanage fcontext 持久化四 AppArmor 作为替代或补充
/etc/apparmor.d/sudo aa-enforce /usr/sbin.httpd、sudo aa-complain /usr/sbin.httpdsudo apparmor_parser -r /etc/apparmor.d/usr.sbin.httpd、sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.httpd五 安全加固与运维实践
sudo apt update && sudo apt upgrade -ysudo apt install unattended-upgrades -y && sudo dpkg-reconfigure unattended-upgradesAllowUsers alice