chmod with numbers: 644, 755 and 600
Learn what chmod 755, 644 and 600 mean, how r=4, w=2 and x=1 add up, and set octal permissions yourself in a practice terminal in your browser.
Instead of letters, chmod also takes three digits: one for the user (owner), one for the group and one for others. Each digit is a sum:
| Permission | Value |
|---|---|
| read (r) | 4 |
| write (w) | 2 |
| execute (x) | 1 |
So 7 = 4 + 2 + 1 = rwx, 6 = 4 + 2 = rw-, 5 = 4 + 1 = r-x, 4 = r-- and 0 = ---.
The ones you'll see most
| Mode | Letters | Typical use |
|---|---|---|
| 644 | rw-r--r-- | ordinary files: you edit, everyone reads |
| 600 | rw------- | private files: only you read or write |
| 755 | rwxr-xr-x | programs, scripts and directories: you change, everyone runs or enters |
| 700 | rwx------ | private scripts or directories |
chmod 600 diary.txtls -l diary.txtThe digits set all nine permissions at once, while letters like u+x change just one. Both are fine; numbers are quicker when you know the result you want.
Careful:You'll sometimes see chmod 777 suggested to "fix" a permission error. It lets everyone change and run the file. It's almost never the right answer.
Your turn
Make diary.txt private (only you can read and write it: rw-------), make scripts/deploy.sh 755 (rwxr-xr-x), and let everyone read public/index.html while only you can change it (rw-r--r--).
Your task
Make diary.txt private (only you can read and write it: rw-------), make scripts/deploy.sh 755 (rwxr-xr-x), and let everyone read public/index.html while only you can change it (rw-r--r--).
- diary.txt is 600 (rw-------) (not done yet)
- scripts/deploy.sh is 755 (rwxr-xr-x) (not done yet)
- public/index.html is 644 (rw-r--r--) (not done yet)
The checklist ticks itself off as you work in the terminal: any way that gets the result counts.
Hints come one at a time, then one way to do it. Try each before the next.
What this lesson uses, in one place.
chmod 600- rw-------: you can read and change it, nobody else can do anything More on chmod →
chmod 755- rwxr-xr-x: you can do everything; others can read and run it More on chmod →
chmod 644- rw-r--r--: you can read and change it; others can only read it More on chmod →