chmod 400
The owner can read the file and nobody can change it, the owner included. Known from the key files of AWS, which have to be set to it.
| Read (4) | Write (2) | Execute (1) | Digit | |
|---|---|---|---|---|
| Owner | 4 | |||
| Group | 0 | |||
| Others | 0 |
A program runs with the rights of the file's owner.
A program runs with the file's group. In a directory, new files get the directory's group.
In a directory, users can't delete or rename each other's files.
Owner can read. Group and others have no access.
chmod 400 filechmod u=r,g=,o= fileCommon values
What 400 allows
| Who | Digit | On a file | On a directory |
|---|---|---|---|
| Owner | 4 r-- | read | see the names, nothing more |
| Group | 0 --- | nothing | nothing |
| Others | 0 --- | nothing | nothing |
ls -l shows this mode as -r-------- on a file and as dr-------- on a directory.
The owner can read the file and nobody can change it, the owner included. A program that tries to write to it gets "Permission denied".
Where it belongs
- Key files. The
.pemfiles that AWS hands out for its servers are the best-known case: its instructions have you runchmod 400 my-key.pembefore connecting withssh -i. SSH itself only demands that nobody else can read the key, so 600 passes as well. - Files that must not change by accident: a certificate, an archive, a licence file.
What it doesn't protect against
The owner can still delete the file, because deleting is decided by the directory and not by the file. The owner can also set the mode back with chmod 600 at any moment, and root isn't stopped by permissions at all. 400 guards against slips, not against intent. A file that has to be truly unchangeable needs something else, such as chattr +i on Linux.
The chmod calculator explains how the digits are built, and what setuid, setgid and the sticky bit add to them.