chmod 664: Group Writable Files for Shared Work
664 is rw-rw-r--: the owner and the owning group can read and write, everyone else can read. It is the file counterpart to a 775 directory and the default file mode on systems that use a umask of 002.
At a glance
- Octal
- 664, written 0664 in four digit form
- Symbolic
- u=rw,g=rw,o=r
- On a file
- -rw-rw-r--
- On a directory
- drw-rw-r--, which cannot be entered because execute is missing
- Owner
- Read and write
- Group
- Read and write. This is the collaboration mechanism
- Others
- Read only. Every local account can see the contents
In detail
664 is what a shared document should be. The owning group edits it, everyone else reads it, and nobody outside can change it. Paired with a 2775 directory so that new files inherit the right group, it gives a team a workable shared area without anyone needing to widen anything later.
It is also a default in disguise. Distributions that use per-user private groups set a umask of 002, which produces 664 for new files and 775 for new directories. Because each user's primary group contains only that user, the group write bit is harmless until a file is deliberately moved into a shared group, at which point collaboration works without a chmod.
The others read bit is worth a deliberate thought. Every local account, including service accounts, can read this file. That is fine for documentation, source code on a private build machine or shared data, and wrong for anything with a credential in it, where 660 or 640 is the correct choice depending on whether the group needs to write.
On a directory 664 does not work, because the execute bit is missing and nothing can traverse in. Shared directories want 775 or 2775. This is the single most common recursive chmod accident: applying a sensible file mode to a whole tree and finding every directory has become unusable.
The security question, as with 775, is about the group rather than the digits. 664 owned by a two person project group is tight. 664 owned by a group that most of the machine belongs to is effectively 666 with extra steps, and should be narrowed to a purpose built group.
Examples
chmod 664 /srv/project/spec.md
chmod u=rw,g=rw,o=r /srv/project/spec.md$ umask
0002
$ touch newfile
$ ls -l newfile
-rw-rw-r-- 1 alice alice 0 newfile
$ umask 022
$ touch otherfile
$ ls -l otherfile
-rw-r--r-- 1 alice alice 0 otherfileThings that catch people out
- 664 on a directory makes it unusable. Directories need the execute bit, so the shared directory counterpart is 775, ideally 2775 so the group is inherited.
- Under a 002 umask the group write bit is set on everything you create. That is safe with per-user private groups and quietly dangerous if you change a file's group to something broad without rechecking the mode.
- SSH and several daemons refuse group writable configuration files outright. A 664 config for one of those tools produces a refusal rather than a warning.
- Every local account can read a 664 file. Do not use it for anything containing a token, password or key, even on a machine you consider private.
Try it: Chmod Calculator
Tick the nine permission boxes, or type an octal or symbolic value, and get the three digit and four digit octal, the ls -l rendering and the exact chmod command back.
Chmod Calculator
LOCAL · Browser-OnlyCalculate Unix file permissions with an interactive chmod builder
Permission Matrix
| Entity | Read (4) | Write (2) | Execute (1) | Octal | Symbolic |
|---|---|---|---|---|---|
| Owner (u) | 7 | rwx | |||
| Group (g) | 5 | r-x | |||
| Others (o) | 5 | r-x |
Special Bits
Advanced permission flags for executables and directories
Generated Permissions
755rwxr-xr-x-rwxr-xr-xchmod 755 filenamechmod u=rwx,g=rx,o=rx filenamePermission Breakdown
Owner (u)
7rwx- - Read files / list directory contents
- - Write / modify / delete
- - Execute / traverse directory
Group (g)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Others (o)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Common Permissions Reference
| Octal | Symbolic | Meaning |
|---|---|---|
777 | rwxrwxrwx | Full access for everyone |
755 | rwxr-xr-x | Owner full, others read and execute |
750 | rwxr-x--- | Owner full, group read and execute |
700 | rwx------ | Owner full access only |
666 | rw-rw-rw- | Read and write for everyone |
644 | rw-r--r-- | Owner read/write, others read only |
600 | rw------- | Owner read/write only |
555 | r-xr-xr-x | Read and execute for everyone |
444 | r--r--r-- | Read only for everyone |
400 | r-------- | Owner read only |
Related File permissions
All file permissions →chmod 775: Owner and Group Write, Everyone Else Reads
775 gives the owner and group full access and leaves others with read and execute. The correct mode for shared directories, and why it needs setgid.
chmod 644: The Default File Mode and When to Change It
644 gives the owner read and write and everyone else read only. Why it is the default for files under a 022 umask, and the cases where it is wrong.
chmod 640: Configuration Files a Service Group Can Read
640 gives the owner read and write, the group read only, and everyone else nothing. The correct mode for configuration holding credentials.
chmod 2775: The setgid Bit on Directories and on Files
2775 adds the setgid bit to 775 so new files inherit the directory's group. The fix for shared directories where the team cannot edit each other's files.
chmod 622: Write Without Read, and the Old Terminal Mode
622 lets the owner read and write while the group and others can only write. Where this came from, what write without read really allows, and why it is rare.
chmod 600: Owner Only Read and Write for Keys and Secrets
600 gives the owner read and write and nobody else anything. The mode SSH, PostgreSQL and other tools insist on for files holding credentials.
Tools for this
- Chmod Calculator Free online chmod calculator - calculate Unix file permissions with an interactive chmod builder