chmod 664 is rw-rw-r--: the owner and the group can read and write, and everyone else can only read. It is 644 plus write access for the group, and it fits a file that a team edits together.
Octal 664
Symbolic rw-rw-r-- (ls -l: -rw-rw-r--)
Command chmod 664 file
owner 6 read write
group 6 read write
others 4 read
When 664 is the right mode
- A shared project folder where a developer group (for example
devs) edits the same files. - Content that several people maintain, such as a wiki or a web root that a deploy group updates.
- Files created by the user with a private group (see below), where the group is only that person.
Why many new files are 664
New files start from 666 and the umask removes bits. With umask 022 the result is 644, and with umask 002 it is 664. Ubuntu and Debian use umask 002 for ordinary users who have a user private group (a group with the same name that contains only that user), so the extra group write bit gives nobody else access. On a server where users share a group, check umask before you rely on it.
Making a shared folder work
For a team folder, three things have to agree: the group, the folder’s setgid bit, and the umask.
sudo chgrp -R devs /srv/project
sudo chmod -R g+w /srv/project # adds group write: 644 becomes 664, 755 becomes 775
sudo find /srv/project -type d -exec chmod g+s {} + # new files inherit the group "devs"
umask 002 # in each member's shell profile
The s in the group’s execute position (drwxrwsr-x) means that new files and folders get the folder’s group instead of the creator’s group. Without it a colleague’s file belongs to their group, and the rest of the team cannot write to it, even though the folder is 775.
Cautions
- Group write is a real permission. Anyone in the group can change or replace the file, including a service account. Keep groups small and named for a purpose.
- Secrets are never 664. Use 600 for keys and
.envfiles. - Web servers. If the server only needs to read, 644 is enough. Giving the web server’s group write access to code allows an exploited application to rewrite itself.
You can compare modes digit by digit in the chmod calculator. If a colleague gets “Permission denied” anyway, check every folder on the path as well: 403 Forbidden explains the commands for that.
Frequently asked questions
What does chmod 664 mean?
The owner and the group can read and write (6), and everyone else can read (4): rw-rw-r--. It is 644 with write access added for the group.
Why are my new files 664 and not 644?
Your umask is 002 rather than 022. Some systems, such as Ubuntu, give each user a private group and use umask 002 because the group contains only that user. The files are 664 but still safe in that case.
Is 664 safe?
It is as safe as the group is small and trusted. If the group has many members, or a service account that you do not control, then 664 lets all of them change the file. Check who is in the group with getent group NAME.
Why can't my colleague write to a file I created, even though the folder is 775?
The file got the creator's primary group and the creator's umask. If the umask is 022 it is 644, so the group cannot write. Set the folder's setgid bit and use umask 002, or run chmod g+w.
More in this reference
- chmod 400: read-only private files, such as .pem keys
- chmod 600: private files for SSH keys, .env and other secrets
- chmod 644: what rw-r--r-- means and why it is the default for files
- chmod 700: private folders and scripts that only the owner can use
- chmod 755: what rwxr-xr-x means and when to use it
- chmod 775: shared folders and scripts for a group (rwxrwxr-x)
- chmod 777: why it is dangerous and what to do instead