Skip to content

chmod 640

chmod 640 sets rw-r-----: the owner can read and modify the file, members of its group can read it, and everyone else has no access.

Permission matrix

Which permission bits each class has
WhoRead (4)Write (2)Execute (1)Digit
Owner (u)YesYesNo6
Group (g)YesNoNo4
Others (o)NoNoNo0

Execute means different things by type. On a file it lets the kernel run it as a program. On a directory it is search permission: entering it (cd) and reaching the files inside by name. Read on a directory only lists names.

What each class can do with a file and with a directory
WhoOn a fileOn a directory
Owner (u)Read and modifyList names only; write does nothing without execute
Group (g)Read the contentsList names only; cannot enter or open entries
Others (o)No accessNo access

Facts

Representations of this mode
Octal640 (0640)
Symbolicrw-r-----
ls -l, file-rw-r-----
ls -l, directorydrw-r-----
Equivalent symbolic commandchmod u=rw,g=r,o=
Default umask that creates itumask 027 for new files
How Git records a file with it100644 (not executable)
Special bitsNone

When to use it

  • Configuration with credentials that a service reads through its group: owner root or deploy, group www-data, mode 640.
  • Log files: Debian and Ubuntu write many files in /var/log as 640 with group adm, so admins read them without sudo while normal users cannot.
  • Web files where the server reads via its group (WordPress accepts 640 for files). It is what new files get under umask 027.

When not to use it

  • When the process reading the file is neither owner nor in the group: it gets permission denied.
  • SSH private keys: ssh refuses a key the group can read. Use 600.
  • Files the group must update: use 660.

Commands

Set it on one file or directory
chmod 640 config.env
chmod u=rw,g=r,o= config.env   # same result
Check the result
stat -c '%a %A %n' config.env     # Linux (GNU stat): 640 -rw-r-----
stat -f '%Lp %Sp %N' config.env   # macOS and BSD

Applying it to a whole tree

chmod -R would put the same mode on files and directories alike. Set directories to 750 and files to 640 separately:

find . -type d -exec chmod 750 {} +
find . -type f -exec chmod 640 {} +

Or in one pass with a capital X, which adds execute only to directories and to files that already had it: chmod -R u=rwX,g=rX,o= ..

Git and the execute bit

Git stores only one permission fact per file: 100755 if the owner execute bit is set, 100644 otherwise. A file with this mode is committed as 100644; the group and others bits never reach the repository. On Windows, or where core.fileMode is false, set the bit with git update-index --chmod=+x.

Frequently asked questions

What does chmod 640 mean?
Owner 6 (rw-), group 4 (r--), others 0 (---).
What is the difference between 640 and 644?
Others. 644 lets every account read the file; 640 limits reading to the owner and the group.
Should a .env file be 640 or 600?
600 if the app runs as the file owner, 640 if the owner is a deploy user and the app reads it through its group.

Last reviewed by Arielton Oberek.