Skip to the content

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
Owner4
Group0
Others0

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 file
chmod u=r,g=,o= file

Common values

Share this tool:TwitterFacebookLinkedInWhatsAppEmail

What 400 allows

WhoDigitOn a fileOn a directory
Owner4 r--readsee the names, nothing more
Group0 ---nothingnothing
Others0 ---nothingnothing

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 .pem files that AWS hands out for its servers are the best-known case: its instructions have you run chmod 400 my-key.pem before connecting with ssh -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.

See all 12