Linux file permissions
chmod 640: what it means and when to use it
chmod 640 lets the owner edit a file and a designated group read it, with zero access for everyone else.
640
rw-r-----
| Who | Digit | Read | Write | Execute |
|---|---|---|---|---|
| Owner | 6 |
Yes | Yes | No |
| Group | 4 |
Yes | No | No |
| Everyone else | 0 |
No | No | No |
How chmod 640 works
Think of 640 as the file equivalent of 750. Neither group nor world receives execute permission, and only the owner can modify the contents.
Package managers and Linux distributions commonly assign 640 to system logs owned by root and the adm group, and to app configuration files holding API keys that a non-root service user must read at startup.
Where 640 belongs
- Environment files and config secrets read by a service group
- System log files readable by monitoring or adm group members
- Database backups shared with a backup group but hidden from local users
The command
Both of these set exactly the same permissions. The number is shorter; the letters are easier to read back later.
chmod 640 filename
chmod u=rw,g=r,o= filename
On directories, 640 lacks the execute bit (1), so nobody can cd into the directory or access files inside it. Directories need 750 instead.