Permissions
| Who | Read (4) | Write (2) | Run (1) | Digit |
|---|---|---|---|---|
| Owner | ||||
| Group | ||||
| Everyone else | ||||
| Special |
Commands
Warning: chmod -R gives every file and folder inside the same mode, so files end up runnable or folders can't be opened. Tick "It's a folder" to get find commands that set folders and files separately.
Folders need x to be opened, and files usually don't, so the find commands set them separately. Files get the same mode without x or setgid.
Common permissions
| Mode | ls -l | Letters | Used for |
|---|---|---|---|
| -rw-r--r-- | u=rw,go=r | Most files: the owner can change them, everyone can read them | |
| -rwxr-xr-x | u=rwx,go=rx | Scripts and programs, so everyone can run them | |
| drwxr-xr-x | u=rwx,go=rx | Most folders | |
| -rw------- | u=rw,go= | Private files: SSH keys, .env files, passwords | |
| drwx------ | u=rwx,go= | Private folders, such as ~/.ssh | |
| -r-------- | u=r,go= | Read-only private files, such as an AWS .pem key | |
| -rw-r----- | u=rw,g=r,o= | Config files a service's group needs to read | |
| drwxr-x--- | u=rwx,g=rx,o= | Folders shared with one group | |
| -rw-rw-r-- | ug=rw,o=r | Files a team edits together through a shared group | |
| drwxrwsr-x | u=rwx,g=rwxs,o=rx | Team folders, where new files keep the folder's group | |
| drwxrwxrwt | ug=rwx,o=rwxt | Shared drop folders like /tmp, where people can only delete their own files | |
| -rwsr-xr-x | u=rwxs,go=rx | Programs that need their owner's rights, like passwd |
How it works
Each file and folder has three sets of permissions: for its owner, for its group, and for everyone else. Each set adds up read (4), write (2) and run (1), so 7 is all three, 5 is read and run, and 4 is read only. 755 means 7 for the owner, 5 for the group and 5 for everyone else.
On a folder, read lets you list what's inside, write lets you add, rename and delete files in it, and run (x) lets you open it and reach the files inside.
A fourth digit in front sets the special bits: setuid (4), setgid (2) and sticky (1). 2775 is 775 plus setgid.
Letters change a mode instead of replacing it. u, g, o and a pick the owner, the group, everyone else or all three. + adds, - removes and = sets exactly. With no u, g, o or a, your umask decides who's affected, so +w usually only reaches the owner. X adds run only to folders and to files someone can already run.
See Linux: Permissions for chown, umask and the other commands that go with it.