Linux File Permissions Explained
Changing Permissions with chmod
chmod — change mode — is how you set permissions. It has two syntaxes: symbolic and octal.
Symbolic mode
You target a group and add (+), remove (-) or set (=) a permission:
chmod u+x script.sh # owner (u) gets execute
chmod g-w notes.txt # group (g) loses write
chmod o=r notes.txt # others (o) are set to read-only
chmod a+r notes.txt # everyone (a = all) gets read
chmod u+x,g-w notes.txt # combine with a comma
| Reference | Group |
|---|---|
u |
owner (user) |
g |
group |
o |
others |
a |
all three |
Octal mode
Each permission has a number: read 4, write 2, execute 1. Add them up per group:
rwx = 7 rw- = 6 r-x = 5 r-- = 4
chmod 755 script.sh # rwxr-xr-x — common for executables
chmod 644 notes.txt # rw-r--r-- — common for files
chmod 600 secret.txt # rw------- — private to the owner
chmod 700 ~/.ssh # rwx------ — private directory
How to remember
Remember 7 = rwx. Then subtract what you don't want: 755 is "rwx for owner, r-x for everyone else".
The classic examples
| Mode | Result | Typical use |
|---|---|---|
644 |
-rw-r--r-- |
Web files, documents |
755 |
-rwxr-xr-x |
Executables, scripts, directories |
700 |
-rwx------ |
Private scripts, .ssh |
600 |
-rw------- |
Secrets, private data |
Why not `chmod 777`?
777 gives read, write and execute to everyone — including write access. It breaks security and is almost never the right answer. Prefer the most restrictive mode that still works.
Try it
touch prog.shthenchmod +x prog.sh && ls -l prog.shchmod 644 prog.sh— see thexdisappear- Create a directory
chmod 700 privateand verify withls -ld
Advertisement