chmod 664 (rw-rw-r--)
Answer
chmod 664 sets rw-rw-r--: the owner and every member of the file's group can read and write it; everyone else can only read it. It is the file mode for collaboration through a shared group.
chmod 664 = rw-rw-r--: owner read and write, group read and write, others read.
| Read 4 | Write 2 | Execute 1 | Digit | |
|---|---|---|---|---|
| Owner (user) | 6 | |||
| Group | 6 | |||
| Others | 4 | |||
| Special | 0 |
6Owner (user): 6 = 4 read + 2 write6Group: 6 = 4 read + 2 write4Others: 4 = 4 read
On a file
- Owner (user) read it and change it
- Group read it and change it
- Others read it
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; write without x does nothing useful (names only: without x the files cannot be opened or even stat'ed)
- Others list the names inside (names only: without x the files cannot be opened or even stat'ed)
chmod 664 filechmod u=rw,g=rw,o=r filels -l → -rw-rw-r--
What to know
The difference from 644 is the middle digit: group members can edit, not just read. That only helps if the file's group is a group your collaborators are in, which is what a setgid directory (2775) arranges for new files.
664 is what new files get under umask 002, which some distributions use for ordinary users who each have a private group of their own.
Where it fits
- Files in a shared project directory owned by a team group
- Web content edited by several deploy users through a common group
- Files under a user-private-group setup, where the group contains only the owner
Gotchas
- Group write is only as safe as the group membership. If the group is a broad one such as
users, every member can change the file. - Check which group the file actually has (
ls -l). Files created outside a setgid directory get the creator's primary group, so collaborators may not be able to edit them. - Others can still read a 664 file. For team-only data use 660.
Related explainers
- chmod 775 (rwxrwxr-x)chmod 775 gives the owner and group full access and others read and execute. Used for shared directories;...
- chmod 2775: setgid directory (rwxrwsr-x)chmod 2775 makes a directory shared: files created in it inherit its group. How to set up a team directory...
- chmod 644 (rw-r--r--)chmod 644 lets the owner read and write a file while everyone else can only read it. The default for...
- umask 002umask 002 creates files as 664 and directories as 775, so your group can edit what you create. When to use...