Home › Guides › chmod and Permissions
Linux File Permissions and chmod, Explained
Every file and directory on Linux and macOS has three sets of permissions: for its owner, for its group, and for everyone else. chmod changes them, using either numbers like 755 or letters like u+x. This guide explains both notations, the permissions you'll use 95% of the time, what the special bits do, and the chmod -R mistake that makes every file executable. Use Chmod Master to convert between octal, symbolic and a checkbox grid as you read.
Reading ls -l
-rwxr-xr-- 1 alice devs 4096 Nov 22 10:00 deploy.sh
The first character is the type (- file, d directory, l symlink). The next nine are three groups of three:
| Owner (u) | Group (g) | Others (o) | |
|---|---|---|---|
| Characters | rwx | r-x | r-- |
| Meaning | read, write, execute | read, execute | read only |
| Octal | 4+2+1 = 7 | 4+0+1 = 5 | 4+0+0 = 4 |
So this file is 754. Each digit is the sum of read (4), write (2) and execute (1) for one class of user.
What r, w and x mean for directories
On a file the letters mean what you'd expect. On a directory they're different, and this is behind many "permission denied" puzzles:
- r lets you list the names inside (
ls). - w lets you create, delete and rename entries inside, but only together with x. Deleting a file depends on the directory's permissions, not the file's.
- x lets you enter the directory and reach things inside it by name. Without x on every parent directory, you can't open a file even if the file itself is readable.
The permissions you'll actually use
| Octal | Symbolic | Typical use |
|---|---|---|
644 | rw-r--r-- | Regular files: web pages, config, source code |
755 | rwxr-xr-x | Directories and scripts or programs everyone may run |
600 | rw------- | Private files: SSH private keys, .env files, credentials |
700 | rwx------ | Private directories such as ~/.ssh |
640 | rw-r----- | Files a service group needs to read, but not everyone |
775 | rwxrwxr-x | Directories shared by a team group |
777 | rwxrwxrwx | Almost never. Anyone on the system can change or replace the file. |
SSH is strict about this: if your private key is readable by others, ssh refuses to use it with "UNPROTECTED PRIVATE KEY FILE". chmod 600 ~/.ssh/id_ed25519 and chmod 700 ~/.ssh fix it.
Symbolic notation
Instead of setting all nine bits, you can change some of them: who (u, g, o, or a for all), an operator (+ add, - remove, = set exactly), and the permissions.
chmod u+x deploy.sh # owner can execute
chmod go-w config.yml # group and others lose write
chmod a=r notes.txt # everyone read-only (444)
chmod u=rwx,g=rx,o= app # same as 750
Symbolic changes are safer when you only want to add or remove one thing, because they leave the other bits alone.
Setuid, setgid and the sticky bit
A fourth, leading octal digit holds three special bits:
- 4 – setuid on an executable: it runs with the file owner's privileges. That's how
passwdcan update a root-owned file. Avoid setting it on your own scripts; it's a common privilege-escalation route. - 2 – setgid on a directory: new files inside inherit the directory's group instead of the creator's main group. Handy for team folders:
chmod 2775 /srv/shared. - 1 – sticky bit on a directory: only a file's owner (or root) can delete or rename it, even though everyone can write to the directory.
/tmpis1777for this reason.
In ls -l they replace the x in their position: s or t when x is also set, and uppercase S or T when it isn't (which is usually a mistake).
The chmod -R trap
chmod -R 755 mysite/ looks harmless but makes every file executable, not just the directories. Set files and directories separately:
find mysite -type d -exec chmod 755 {} +
find mysite -type f -exec chmod 644 {} +
Or use the capital X, which adds execute only to directories and to files that already have execute for someone: chmod -R u=rwX,go=rX mysite.
umask: where default permissions come from
New files start from 666 and new directories from 777, then the bits in your umask are removed. With the common umask 022, new files are 644 and new directories 755. With 077, they are 600 and 700, private to you. Run umask to see yours.
Related tools
- Chmod Master: convert between octal, symbolic and a checkbox grid, including setuid, setgid and sticky.
- Gitignore Forge: keep
.envand key files out of your repository in the first place.