chmod or chown command.
Understanding Unix File Permissions
Every file and directory on a Linux or macOS system has three permission sets — owner, group, and others — each containing three bits: read (r), write (w), and execute (x).Reading ls -l Output
Breaking down the permission string
Breaking down the permission string
The ten-character string
-rw-r--r-- is read left to right:Octal notation quick reference
Octal notation quick reference
Permissions are often expressed as a three-digit octal number:
So
644 means owner=rw, group=r, others=r. And 755 means owner=rwx, group=rx, others=rx.The execute bit on directories
The execute bit on directories
For directories, the execute bit means “traverse” — without it, users cannot
cd into the directory or access files within it, even if they have read permission on individual files inside. A directory set to 644 is almost always a mistake.Step-by-Step Permission Repair
1
Diagnose the Permission Problem
Start by reading the exact error message and inspecting the permissions on the affected file or directory.
2
Fix File Ownership with chown
chown changes the owner and/or group of a file. Use it when a file is owned by the wrong user — a common occurrence after copying files between accounts or running a command as root.3
Fix File Permissions with chmod
chmod modifies the read, write, and execute bits. Both symbolic and octal notation are accepted.- Octal Notation
- Symbolic Notation
- Directories vs Files (Recursive)
4
Fix Common Permission Scenarios
- Web Server Files (Apache / Nginx)
- SSH Keys
- Home Directory
Web server processes (typically running as
www-data on Debian/Ubuntu or nginx on RHEL) must be able to read your web files — and write to upload directories.For WordPress and similar CMS installations, the web server user often needs write access to the entire document root during upgrades. After upgrading, tighten permissions back to
644/755 and change ownership back to your deploy user.5
Use sudo Safely
sudo grants temporary root-level access. Misusing it is a frequent source of incorrect ownership and permissions — files created as root when they should be owned by a service account or regular user.Quick Reference: Permission Cheat Sheet
Escalation
Permission denied even after chmod/chown
Permission denied even after chmod/chown
Check for SELinux or AppArmor policies that override standard POSIX permissions:
Escalation path
Escalation path
- Record the exact error message, the output of
ls -laon the affected path, and the output ofidfor the affected user. - Check
journalctl -xeor/var/log/syslogfor related audit or denial messages. - Submit a ticket to your systems administrator with the above information. If SELinux or AppArmor is involved, label the ticket accordingly, as policy changes require elevated access.