breakitdown

chmod 640 (rw-r-----)

Answer

chmod 640 sets rw-r-----: the owner can read and write, members of the file's group can only read, and everyone else has no access. It shares a secret with exactly one group.

Try

chmod 640 = rw-r-----: owner read and write, group read, others nothing.

Read 4Write 2Execute 1Digit
Owner (user)6
Group4
Others0
Special0
  1. 6
    Owner (user): 6 = 4 read + 2 write
  2. 4
    Group: 4 = 4 read
  3. 0
    Others: 0 = no permissions

On a file

  • Owner (user) read it and change it
  • Group read it
  • Others no access

On a directory

  • Owner (user) list the names inside; write without x does nothing useful (names only: without x the files cannot be opened or even stat'ed)
  • Group list the names inside (names only: without x the files cannot be opened or even stat'ed)
  • Others no access

chmod 640 filechmod u=rw,g=r,o= filels -l → -rw-r-----

What to know

A common pattern is a config file owned by root (so the service cannot rewrite it) with the service's group and mode 640, so the service can read it but no other local user can.

On Debian and Ubuntu, /etc/shadow is 640 with group shadow: only root can change password hashes, and only programs running with the shadow group can read them.

Where it fits

Gotchas

Related explainers

← chmod calculator