A guide to diagnosing and resolving file permission issues in Linux
File permissions in Linux are a crucial aspect of system security and proper functionality. Understanding and troubleshooting permission issues is an essential skill for any Linux system administrator.
| Permission | Numeric Value |
|---|---|
| Read (r) | 4 |
| Write (w) | 2 |
| Execute (x) | 1 |
Symptom: You encounter a "Permission denied" error when trying to access or modify a file.
Troubleshooting steps:
ls -l filenameidchmod u+rw filenameSymptom: You can't run a shell script, even though you have read access.
Solution:
chmod +x script.sh
Symptom: Your web server (e.g., Apache or Nginx) returns 403 Forbidden errors.
Troubleshooting steps:
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
Symptom: Special permissions are not working as expected.
Troubleshooting:
chmod u+s filenamechmod g+s directorychmod +t directoryWhen standard permissions are not granular enough, use ACLs:
getfacl filename
setfacl -m u:username:rw filename
Use auditd to monitor file access attempts:
auditctl -w /path/to/file -p warx -k file_access_attempt
If SELinux is enabled, check and modify contexts:
ls -Z filename
chcon -t httpd_sys_content_t filename
ls -l: List files with permissionsstat filename: Display detailed file informationnamei -l /path/to/file: Show permissions for each component of a pathfind /path -type f -not -perm 644: Find files with permissions other than 644lsattr and chattr: View and change file attributes