chmod Numeric Mode
You've seen permissions like 755 and 644. Let's understand where those numbers come from.
The Number System
Each permission has a value:
- r (read) = 4
- w (write) = 2
- x (execute) = 1
Add them up for each user class:
rwx = 4+2+1 = 7
rw- = 4+2+0 = 6
r-x = 4+0+1 = 5
r-- = 4+0+0 = 4
Building Permission Numbers
Three digits: owner, group, others.
755 = rwxr-xr-x
│││
││└── Others: 5 = r-x
│└─── Group: 5 = r-x
└──── Owner: 7 = rwx
Common Permission Numbers
| Number | Symbolic | Use Case |
|---|---|---|
644 | -rw-r--r-- | Regular files |
755 | -rwxr-xr-x | Executables, directories |
600 | -rw------- | Private files (SSH keys) |
700 | -rwx------ | Private directories |
666 | -rw-rw-rw- | Rarely used |
777 | -rwxrwxrwx | Avoid - too open |
Numeric vs Symbolic
Same result, different syntax:
| Numeric | Symbolic |
|---|---|
chmod 755 file | chmod u=rwx,go=rx file |
chmod 644 file | chmod u=rw,go=r file |
chmod 600 file | chmod u=rw,go= file |
Numeric is shorter. Symbolic is more readable.
When to Use Which
- Numeric: When you know exactly what you want (755, 644)
- Symbolic: When you're adding/removing specific permissions (u+x, g-w)
Memorize These
Most of the time, you only need these:
| Number | Memory Aid |
|---|---|
755 | Standard directories, executables |
644 | Standard files |
600 | Private sensitive files |
700 | Private directories |
The Calculation
Let's work through chmod 754:
7 = 4+2+1 = rwx (owner)
5 = 4+0+1 = r-x (group)
4 = 4+0+0 = r-- (others)
Result: rwxr-xr--
Going the other way:
rw-r--r-- = ?
Owner: rw- = 4+2+0 = 6
Group: r-- = 4+0+0 = 4
Others: r-- = 4+0+0 = 4
Result: 644
Real-World Usage
Web Files
SSH Keys
SSH is picky about permissions. Too open = won't work.
Scripts
What permission number gives owner full access and everyone else read-only?
Quick Reference
| Permission | Number |
|---|---|
--- | 0 |
--x | 1 |
-w- | 2 |
-wx | 3 |
r-- | 4 |
r-x | 5 |
rw- | 6 |
rwx | 7 |
Key Takeaways
- r=4, w=2, x=1 - add them for each class
- Three digits: owner-group-others
- 755 for executables/directories
- 644 for regular files
- 600/700 for private files/directories
- Numeric is faster, symbolic is clearer
Next: changing file ownership with chown and chgrp.