chmod 664 (rw-rw-r--)
The owner and the members of the file's group can read and write; everyone else can only read. It is the file mode for a project that several accounts edit.
This tool runs in your browser. We never send what you type or paste to a server.
What chmod 664 sets
| Who | Digit | Read | Write | Execute | Symbolic |
|---|---|---|---|---|---|
| Owner (u) | 6 | yes | yes | no | rw- |
| Group (g) | 6 | yes | yes | no | rw- |
| Others (o) | 4 | yes | no | no | r-- |
chmod 664 file # numeric
chmod ug=rw,o=r file # the same, in symbolic form
ls -l shows this mode as -rw-rw-r-- on a file and drw-rw-r-- on a directory. On a file, execute means it can be run as a program. On a directory, read lists the names inside, write creates, renames and deletes entries, and execute (search) is what lets you enter it and reach the files inside.
When 664 is the right mode
Use it when more than one account has to edit the same files: a site that two developers deploy to, a shared data directory, content that both a deploy user and an editor's account write.
The mode is only half of it. 664 hands write access to whichever group the file belongs to, so look at that group first:
ls -l page.html # owner and group are the third and fourth columns
stat -c '%a %U:%G %n' page.html # GNU/Linux: mode, owner:group, name
id alice # which groups alice is in
If the group is the owner's personal group, with no other members, 664 behaves exactly like 644.
umask 002 makes 664 automatic
New files come out as 664, and new directories as 775, when the creating process has a umask of 002 instead of the common 022.
Many Linux distributions give each user a private group with the same name as the user. On those systems a umask of 002 exposes nothing by itself, since the only member of the group is you, and files become group-writable in a useful sense only once they are given to a shared group. PAM's pam_umask module has a usergroups option that applies exactly this rule at login, turning 022 into 002 for users whose primary group matches their user name.
What a shared tree needs besides 664
- The right group on every file.
chgrp -R team projectfixes existing files. For new ones, set the setgid bit on the directories (2775) so that files created there take the directory's group instead of the creator's own. - Group-writable directories. Creating, renaming and deleting are controlled by the directory. In a 755 directory, group members can change the contents of a 664 file but cannot delete it or add a new one next to it.
- Members with umask 002. Otherwise the next file somebody creates is 644 again.
- A fresh login. Someone just added to the group does not get the new membership in sessions that are already running.
chgrp -R team project
find project -type d -exec chmod 2775 {} +
find project -type f -exec chmod 664 {} +
Risks
- Wide groups. If every account is in one common group such as
usersorstaff, 664 means "anyone here can change this". - Group-writable files that get executed. If root's cron job or another user runs or sources a file, every member of the file's group can decide what that code does. Scripts and configuration read by privileged programs should be writable by their owner only.
- SSH. With its default
StrictModessetting, sshd ignores anauthorized_keysfile that is group-writable. Use 600 there.
664 compared with its neighbours
Questions
What is the difference between chmod 664 and 644?
The group write bit. With 644 only the owner can modify the file. With 664 every member of the file's group can as well. Others can read under both. If nobody but the owner is in the group, there is no practical difference.
What umask gives 664?
A umask of 002. New files are requested as 666 and the umask removes the write bit for others, leaving 664; new directories come out as 775. The more common umask of 022 gives 644 and 755.
Why can a colleague not edit the file even though it is 664?
Check three things. The file may belong to a group they are not in, often your own personal group: fix it with chgrp. They may have been added to the group after they logged in, in which case they need a new session. Or their editor saves by replacing the file, which needs write permission on the directory as well.