Understanding Linux File Permissions
Read rwx at a glance, decode 755 vs 644, grasp ownership and sudo, and understand why setuid binaries are a security topic.
"Permission denied" stops being mysterious once you can read the nine little letters Linux shows you.
Reading ls -l
-rwxr-xr-- 1 alice devs 4096 file.sh
│└┬┘└┬┘└┬┘ └─┬─┘ └┬┘
│ │ │ │ │ └ group
│ │ │ │ └ owner (user)
│ │ │ └ others: r-- (read)
│ │ └ group: r-x (read, execute)
│ └ owner: rwx (read, write, execute)
└ type: - file, d directory, l symlinkThree triples: owner, group, others. Each is some combination of r (read), w (write), x (execute).
The numbers: r=4, w=2, x=1
Add them per triple:
rwx= 4+2+1 = 7r-x= 4+0+1 = 5r--= 4+0+0 = 4
So the common ones read as:
| Mode | Means | Typical use |
|---|---|---|
| 755 | owner rwx, group+others r-x | scripts, directories, programs |
| 644 | owner rw, group+others r | normal files |
| 600 | owner rw only | private files (keys, configs) |
| 700 | owner rwx only | private directories |
chmod 644 notes.txt # rw-r--r--
chmod 755 script.sh # rwxr-xr-x
chmod 600 ~/.ssh/id_ed25519 # keep a private key privatex on directories means something different
On a file, x means "runnable." On a directory, x means "may enter / traverse it." A directory usually needs r (list contents) and x (cd into it) together.
Ownership and sudo
Every file has a user owner and a group owner. Change them with chown:
sudo chown alice:devs file.shWhen you lack permission, sudo runs a command as another user (root by default) — but only if policy allows it. That's why you log in as a normal user and escalate deliberately, rather than living as root.
setuid: where permissions become security
A file with the setuid bit runs with the owner's privileges, not yours. passwd is setuid-root so you can change your password (which edits a root-owned file) without being root. That's useful — and dangerous: a buggy setuid-root binary is a privilege-escalation waiting to happen.
find / -perm -4000 -type f 2>/dev/null # list setuid binariesReview that list on a server you manage; unexpected setuid files deserve a hard look.
Takeaways
- Read permissions as three triples (owner/group/others) of r(4) w(2) x(1).
- 755 for programs and directories, 644 for files, 600 for secrets.
xon a directory means "traverse," not "execute."- setuid binaries run as their owner — powerful, and a key privilege-escalation surface; never reach for 777.