Ubuntu Stream 8权限设置指南
Ubuntu Stream 8(基于Ubuntu 20.04 LTS)的权限管理围绕用户/组管理、文件/目录权限及**细粒度控制(如ACL)**展开,以下是具体操作指南:
用户和组是权限分配的基础,通过合理分组可简化权限管理。
adduser命令(交互式,自动创建主目录):sudo adduser new_user
或使用useradd命令(需手动指定主目录):sudo useradd -m new_user && sudo passwd new_user
sudo passwd username(系统会提示输入新密码);-aG表示追加,避免移除原有组):sudo usermod -aG target_group username;sudo chsh -s /bin/bash username(将shell改为bash)。sudo deluser --remove-home username;sudo deluser username。sudo groupadd group_name;sudo groupdel group_name;sudo gpasswd -d username group_name。文件/目录权限控制着用户对其的访问级别,分为读(r)、写(w)、**执行(x)**三类,分别对应用户(owner)、组(group)、其他用户(others)。
ls -l命令查看详细权限(如-rwxr-xr--):ls -l /path/to/file_or_directory
输出解读:-rw-r--r-- 1 user group 4096 Jan 1 12:34 file(用户有读写权限,组和其他用户有读权限)。chmod u+x file;chmod g-w file;chmod o=r file。chmod 755 file(用户:7=4+2+1(读写执行),组和其他:5=4+1(读执行));chmod 644 file(用户:6=4+2(读写),组和其他:4(只读))。chown命令修改文件/目录的所有者和组:sudo chown new_owner:new_group file_or_directory
示例:将/var/www/html的所有者设为www-data,组设为www-data:sudo chown -R www-data:www-data /var/www/html
(-R表示递归修改目录及其子项)。服务权限需确保进程能访问所需文件,同时限制不必要的访问。
/etc/nginx/nginx.conf),确认user指令设置为www-data(默认用户):sudo nano /etc/nginx/nginx.conf
确保有:user www-data;。sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
sudo chown -R www-data:www-data /var/log/nginx
sudo chmod -R 755 /var/log/nginx
sudo systemctl restart nginx
若需更灵活的权限(如给特定用户单独授权),可使用访问控制列表(ACL)。
sudo apt install acl
user1添加对/data目录的读写权限:sudo setfacl -m u:user1:rw /data
dev添加对/data目录的执行权限:sudo setfacl -m g:dev:x /data
sudo getfacl /data
输出会显示详细的权限分配(包括默认ACL)。root权限);777(所有用户可读写执行),易引发安全风险;ls -l或getfacl查看权限,及时撤销不必要的权限。以上步骤覆盖了Ubuntu Stream 8权限管理的核心场景,可根据实际需求调整。操作前建议备份重要数据,避免误操作导致系统故障。