How to read the result
The mode always shows four digits. The first one holds the special bits, so 755 shows as 0755. For a file, both mean the same thing.
The nine letters match what ls -l prints after its first character. That first character is the file type, such as - for a file or d for a directory.
The field takes numbers only. To turn letters such as rwxr-x--- into a number, tick the matching boxes.
A config file only you and your group can read
Example
You want to edit the file, let your group read it, and keep everyone else out. Tick owner read and write, and group read.
The result is 0640, shown as rw-r-----. Owner is 6 (4 + 2), group is 4, and others is 0.
Before you run the command, check the real target with ls -ld path/to/file. It shows the type, owner, group, and current permissions.
How do chmod numbers work?
Each digit adds up three values: read is 4, write is 2, and execute is 1. The three digits are for the owner, the group, and everyone else, in that order.
One permission digit
Formula
read (4) + write (2) + execute (1)
| Digit | Letters | Permissions |
|---|---|---|
| 7 | rwx | Read, write, and execute |
| 6 | rw- | Read and write |
| 5 | r-x | Read and execute |
| 4 | r-- | Read only |
| 3 | -wx | Write and execute |
| 2 | -w- | Write only |
| 1 | --x | Execute only |
| 0 | --- | Nothing |
So 755 gives the owner everything and lets the group and others read and execute. A fourth digit in front adds the special bits, covered below. The GNU chmod manual defines these values.
What do 644, 755, 600, and 777 mean?
These are the modes you'll see most. They're common patterns, not rules. Give a file the fewest permissions that still let its program work.
644(rw-r--r--): ordinary files and web pages. You edit, everyone reads.755(rwxr-xr-x): directories, scripts, and programs. You edit, everyone reads and runs.640(rw-r-----): config files a service's group must read. Others get nothing.600(rw-------): private keys and password files. Only you.700(rwx------): private directories such as~/.ssh. Only you.777(rwxrwxrwx): rarely right. Anyone on the system can change it.
Some programs check this for you. ssh ignores a private key that other users can access.
Why do directories need execute permission?
On a directory, execute means you can enter it and reach the files inside by name. Read only lets you list the names.
| Permission | On a file | On a directory |
|---|---|---|
| Read | Read the contents | List the names inside |
| Write | Change the contents | Add, delete, or rename entries, with execute also set |
| Execute | Run it as a program | Enter it and open entries by name |
This is why one mode for a whole folder tree goes wrong. chmod -R 644 leaves directories without execute, so no one but root can open the files inside. chmod -R 755 makes every file executable.
GNU chmod's capital X handles mixed trees: a+X adds execute only to directories and to files that someone could already execute. See conditional executability.
Deleting a file depends on the directory's write permission, not the file's. A read-only file can still be deleted from a folder you can write to.
What do s, S, t, and T mean in permissions?
They mark the special bits, which sit in the first of the four digits. Each letter takes the place of an x: setuid in the owner's spot, setgid in the group's, and sticky in others'.
| Special bit (first digit) | Letters | What it does |
|---|---|---|
| Setuid (4) | s/S | A program runs with its owner's user ID |
| Setgid (2) | s/S | A program runs with its group's ID. On a directory, new files get the directory's group. |
| Sticky (1) | t/T | On a directory, only a file's owner, the directory's owner, or root can delete or rename it |
Lowercase means the execute bit is also set. Uppercase means it isn't. So 4640 shows as rwSr-----: setuid is on, but the owner can't execute. The GNU ls manual lists these letters.
You'll see two of these on real systems. /tmp is usually 1777 (rwxrwxrwt), so anyone can write there but can't delete other people's files. A shared folder set to 2775 keeps every new file in the folder's group. The Linux inode manual describes both.
Why can't I access a file when the permissions look right?
The mode is only one part of access. These also decide it:
| What else counts | What to check |
|---|---|
| Owner and group | The owner digit applies only to the user who owns the file. Compare the owner in ls -l with the user your program runs as. |
| Parent directories | You need execute on every directory in the path, not just the last one. |
| ACLs | A + after the letters in ls -l means extra rules for named users or groups. getfacl shows them. See the Linux ACL manual. |
| Mount options | A filesystem mounted read-only blocks writes, and one mounted noexec blocks running programs, whatever the mode says. |
| Containers | In an unprivileged container, files owned by an unmapped user show up as nobody (ID 65534). The LXC ID mapping checker checks those mappings. |
Is umask the same as chmod?
No. Umask removes permissions when a file is created. chmod sets them on a file that already exists.
The usual umask is 022. A program that creates a file with 666 gets 644, and a directory created with 777 gets 755. Changing the umask doesn't touch existing files. See the Linux umask manual.