chmod 640
The owner can read and write, the group can only read, and others have no access. For log files and configuration with something to hide.
| Read (4) | Write (2) | Execute (1) | Digit | |
|---|---|---|---|---|
| Owner | 6 | |||
| Group | 4 | |||
| 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 and write. Group can read. Others have no access.
chmod 640 filechmod u=rw,g=r,o= fileCommon values
What 640 allows
| Who | Digit | On a file | On a directory |
|---|---|---|---|
| Owner | 6 rw- | read and change | see the names, nothing more |
| Group | 4 r-- | read | see the names, nothing more |
| Others | 0 --- | nothing | nothing |
ls -l shows this mode as -rw-r----- on a file and as drw-r----- on a directory.
The owner can edit the file, members of the group can read it, and others get nothing.
Where it belongs
Files that one account writes and a few others have to read:
- Log files. On Debian and Ubuntu
/var/log/syslogis 640 with the groupadm, so that administrators in that group can read the logs and ordinary users can't. - Configuration with passwords in it. Owned by root, with the group of the service that needs it: root can edit the file, the service can read it and nobody else can.
/etc/shadow, the file with the password hashes, is 640 on Debian-based systems, with a group of its own.
Next to 644 and 600
644 lets everyone read, 600 nobody but the owner. 640 sits between them, and it is only as good as the choice of group. Check with ls -l which group the file has, and who is in it.
For a directory the matching mode is 750.
The chmod calculator explains how the digits are built, and what setuid, setgid and the sticky bit add to them.