在Ubuntu系统中,合理的文件权限设置对于确保系统安全和正常运行至关重要。以下是一些建议的文件权限设置:
-rw-r--r-- (644):所有者可读写,组用户和其他用户可读。drwxr-xr-x (755):所有者可读写执行,组用户和其他用户可读执行。-rwxr-xr-x (755):所有者可读写执行,组用户和其他用户可读执行。$USER)700 (drwx------)chmod 700 ~
600 (rw-------)chmod 600 /etc/passwd
chmod 600 /etc/shadow
755 (drwxr-xr-x) 或 644 (rw-r–r–)chmod 755 /var/www/html
chmod 644 /var/www/html/index.html
640 (rw-r-----)chmod 640 /var/log/syslog
umask设置默认权限umask命令可以用来设置新创建文件和目录的默认权限掩码。
umask 022:新文件默认权限为644,新目录默认权限为755。umask 002:新文件默认权限为664,新目录默认权限为775。chown和chgrp更改所有者和组sudo chown username:groupname filename
sudo chown :groupname filename
chmod更改权限chmod u+x file # 给所有者添加执行权限
chmod g-w file # 移除组的写权限
chmod o=r file # 设置其他用户的权限为只读
chmod 755 file # 设置所有者读写执行,组和其他用户读执行
chmod 644 file # 设置所有者读写,组和其他用户只读
setfacl设置访问控制列表(ACL)ACL提供了比传统权限更细粒度的控制。
sudo setfacl -m u:username:rwx file # 给特定用户添加读写执行权限
sudo setfacl -m g:groupname:rwx file # 给特定组添加读写执行权限
定期检查文件和目录的权限,确保它们仍然符合当前的安全需求。
通过遵循这些建议,你可以设置一个既安全又高效的Ubuntu文件权限系统。