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.

· 2 min read · beginner

"Permission denied" stops being mysterious once you can read the nine little letters Linux shows you.

Reading ls -l

text
-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 symlink

Three 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 = 7
  • r-x = 4+0+1 = 5
  • r-- = 4+0+0 = 4

So the common ones read as:

ModeMeansTypical use
755owner rwx, group+others r-xscripts, directories, programs
644owner rw, group+others rnormal files
600owner rw onlyprivate files (keys, configs)
700owner rwx onlyprivate directories
bash
chmod 644 notes.txt     # rw-r--r--
chmod 755 script.sh     # rwxr-xr-x
chmod 600 ~/.ssh/id_ed25519   # keep a private key private

x 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:

bash
sudo chown alice:devs file.sh

When 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.

bash
find / -perm -4000 -type f 2>/dev/null    # list setuid binaries

Review 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.
  • x on a directory means "traverse," not "execute."
  • setuid binaries run as their owner — powerful, and a key privilege-escalation surface; never reach for 777.

Related

Linux beginner

Essential Shell One-Liners

The pipes and filters that turn the terminal into a power tool — find, grep, sort, awk and xargs, composed into commands you'll reuse daily.

· 2 min read