How Linux file permissions work
Every file and directory has three sets of permissions: for its owner, its group, and others (everyone else). Each set has three bits:
| Permission | Letter | Value | On a file | On a directory |
|---|---|---|---|---|
| Read | r | 4 | View contents | List file names |
| Write | w | 2 | Modify contents | Create, delete, rename entries |
| Execute | x | 1 | Run as a program | Enter it (cd) and access files inside |
Add the values to get one digit per set. For example, read + write = 4 + 2 = 6. Three digits, for
owner, group and others, make the octal mode: 644.
Common chmod values
| Octal | Symbolic | Typical use |
|---|---|---|
644 |
rw-r--r-- |
Regular files: owner can edit, everyone can read. Default for web files. |
755 |
rwxr-xr-x |
Directories and executables: owner has full access, others can read and enter or run. |
600 |
rw------- |
Private files: SSH private keys, .env files, credentials. |
700 |
rwx------ |
Private directories, e.g. ~/.ssh. |
664 |
rw-rw-r-- |
Files shared with a group that can also edit them. |
775 |
rwxrwxr-x |
Shared directories where the group can add files. |
400 |
r-------- |
Read-only for the owner, e.g. AWS .pem keys. |
777 |
rwxrwxrwx |
Everyone can do everything. Almost never the right answer. |
Every mode has its own page with a full breakdown, safety notes and commands: 777 · 775 · 770 · 755 · 751 · 750 · 744 · 711 · 700 · 666 · 664 · 660 · 644 · 640 · 600 · 555 · 500 · 444 · 400 · 000 · 1777 · 2775 · 4755
Special permissions
A fourth leading digit sets special bits:
-
4 – setuid (
chmod 4755): an executable runs as its owner. This is howpasswdcan update/etc/shadow. -
2 – setgid (
chmod 2775): on a directory, new files inherit the directory's group. This is great for shared project folders. -
1 – sticky bit (
chmod 1777): in a shared directory, only a file's owner can delete it, as in/tmp.
Handy chmod commands
# Make a script executable for its owner
chmod u+x deploy.sh
# Directories 755, files 644, recursively (the safe way)
find /var/www/site -type d -exec chmod 755 {} +
find /var/www/site -type f -exec chmod 644 {} +
# Fix SSH key permissions
chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_ed25519
# Show permissions as octal
stat -c '%a %n' * # Linux
stat -f '%Lp %N' * # macOS
Avoid chmod -R 755 on a whole tree. It makes every file executable. Use the find pattern
above to treat files and directories differently.
Frequently asked questions
What does chmod 755 mean?
755 gives the owner read, write and execute (7 = 4+2+1), and gives the group and everyone else read and execute (5 = 4+1). In symbolic form that is rwxr-xr-x. It is the standard permission for directories and scripts.
What is the difference between 644 and 755?
Both let only the owner write. 755 adds execute permission for everyone. On a file, execute lets it run as a program. On a directory, it lets users enter and access files inside. Use 644 for regular files and 755 for directories and scripts.
Why is chmod 777 dangerous?
777 lets every user on the system modify or replace the file, so any compromised process or user account could inject code. If something only works with 777, the real fix is usually correcting the owner with chown, or adding the right user to the file’s group.
What permissions should an SSH private key have?
The private key (e.g. ~/.ssh/id_ed25519) must be 600 or 400, and ~/.ssh itself should be 700. OpenSSH refuses to use a private key that other users can read, with the error "UNPROTECTED PRIVATE KEY FILE".
What do the s and t letters mean in permissions?
s in the owner or group execute position means setuid or setgid, so the program runs with the file owner’s or group’s privileges. t in the others position is the sticky bit: in a directory like /tmp, users can only delete their own files. Capital S or T means the special bit is set but execute is not.