The Plain Picture#
An office document has three kinds of people: the owner, people in the owner's team, and everyone else. For each kind you decide: may they read it, change it, run it (if it's a program)?
The Real Names#
Every file has an owner (a user) and a group (a named set of users).
There are three permission bits for each of three classes:
-rwxr-xr--
└┬┘└┬┘└┬┘
│ │ └─ others: r-- read only
│ └──── group: r-x read and execute
└─────── owner: rwx read, write, execute| Letter | On a file | On a directory |
|---|---|---|
r read | view the contents | list the names inside |
w write | change the contents | create, delete or rename files inside |
x execute | run it as a program | enter it (cd) and reach files inside |
root is the superuser (user ID 0). Permissions don't apply to root — it can read, change or delete anything.
sudo("superuser do") runs one command as root, after checking you're allowed:sudo systemctl restart nginx.
Under the Hood — numbers#
Each class's three bits form a binary number (How Computers Work Ch 2): r = 4, w = 2, x = 1.
rwx = 4+2+1 = 7 r-x = 4+0+1 = 5 r-- = 4 rw- = 4+2 = 6 --- = 0So three digits describe everything:
| Number | Letters | Typical use |
|---|---|---|
| 755 | rwxr-xr-x | programs, scripts, directories — everyone may run/enter, only the owner may change |
| 644 | rw-r--r-- | normal files — everyone reads, only the owner writes (your access.log above had exactly this) |
| 600 | rw------- | secrets: SSH private keys, .env files — only the owner |
| 700 | rwx------ | a private directory, e.g. ~/.ssh |
| 777 | rwxrwxrwx | everyone can do everything — almost always a mistake |
chmod 600 ~/.ssh/id_ed25519 # set by number
chmod +x deploy.sh # add execute for everyone (letters form)
chmod u+x,g-w file # owner +execute, group −write
chown priya:devs report.txt # change owner and group (needs sudo unless you're root)
id # who am I, and which groups am I in?Default permissions: new files get their permissions from a mask called umask. The usual umask is 022,
meaning "remove write for group and others", so new files come out as 644 and new directories as 755.
Gotchas
"Permission denied" on a script you just wrote → it isn't executable:
chmod +x script.sh.SSH refuses a private key with "UNPROTECTED PRIVATE KEY FILE" if its permissions are too open →
chmod 600.chmod -R 777to "fix" a permission error is the classic dangerous shortcut: now any user or compromised process can modify your files. Find the real owner/permission problem instead.Don't run your app as root. If it's hacked, the attacker becomes root. Run it as its own low-privilege user (principle of least privilege, Networking 2: TCP, UDP and Ports Ch 11). This matters again inside Docker (Docker (coming soon)).
Check yourself
4 questionsWhat does chmod 754 run.sh allow for owner, group and others?
Show answerHide answer
Owner rwx (7), group r-x (5), others r-- (4).
What permissions should an SSH private key have?
Show answerHide answer
600 — read/write for the owner only.
On a directory, what does the x bit allow?
Show answerHide answer
Entering it and accessing the files inside.
Why is running your web app as root dangerous?
Show answerHide answer
If the app is compromised, the attacker gets full control of the whole machine.