chmod 2775
chmod 2775 sets rwxrwsr-x: owner and group have full access, others can read and enter, and the setgid bit (the s) makes files and subdirectories created inside inherit the directory's group instead of the creator's primary group.
Permission matrix
| Who | Read (4) | Write (2) | Execute (1) | Digit |
|---|---|---|---|---|
| Owner (u) | Yes | Yes | Yes | 7 |
| Group (g) | Yes | Yes | Yes | 7 |
| Others (o) | Yes | No | Yes | 5 |
Execute means different things by type. On a file it lets the kernel run it as a program. On a directory it is search permission: entering it (cd) and reaching the files inside by name. Read on a directory only lists names.
| Who | On a file | On a directory |
|---|---|---|
| Owner (u) | Read, modify and run | List, enter, create, delete and rename entries |
| Group (g) | Read, modify and run | List, enter, create, delete and rename entries |
| Others (o) | Read and run | List, enter and open entries |
Special bits in this mode
- setgid (2000): a program runs with the file's group; on a directory, new files and subdirectories inherit the directory's group.
Facts
| Octal | 2775 |
|---|---|
| Symbolic | rwxrwsr-x |
| ls -l, file | -rwxrwsr-x |
| ls -l, directory | drwxrwsr-x |
| Equivalent symbolic command | chmod u=rwx,g=rwxs,o=rx |
| Default umask that creates it | None of the common umasks; set it explicitly with chmod |
| How Git records a file with it | 100755 (executable) |
| Special bits | setgid |
When to use it
- Shared project, deploy or web directories edited by several people in one group. Without setgid, a file Alice creates gets group alice, and Bob cannot edit it.
- Together with umask 002 (or 007), so the new files are also group-writable: the setgid bit fixes the group, the umask fixes the mode.
When not to use it
- On regular files: setgid on an executable runs it with the file's group privileges, which is not what you want for data.
- When others must not read the project: use 2770.
Setting up a shared folder from scratch
Setgid only affects files created after it is set, so fix the group of existing content first. Subdirectories created later inherit the setgid bit themselves, so the arrangement propagates down the tree.
GNU chmod keeps a directory's setgid bit when you later run chmod 775 on it (a GNU extension described in the coreutils manual). Remove it explicitly with chmod g-s, or with a five-digit mode such as 00775.
sudo groupadd devs
sudo usermod -aG devs alice # alice logs in again to pick it up
sudo chgrp -R devs /srv/projects
# then the two find commands below set 2775 on directories and 664 on filesCommands
sudo chmod 2775 /srv/projects
sudo chmod u=rwx,g=rwxs,o=rx /srv/projects # same resultstat -c '%a %A %n' /srv/projects # Linux (GNU stat): 2775 drwxrwsr-x
stat -f '%Mp%Lp %Sp %N' /srv/projects # macOS and BSDApplying it to a whole tree
chmod -R would put the same mode on files and directories alike. Set directories to 2775 and files to 664 separately:
sudo find /srv/projects -type d -exec chmod 2775 {} +
sudo find /srv/projects -type f -exec chmod 664 {} +Frequently asked questions
- What does the 2 in chmod 2775 mean?
- It is the setgid bit (octal 2000). On a directory it makes new entries inherit the directory's group; ls -l shows it as an s in the group execute slot.
- Why do new files in my shared folder still have the wrong permissions?
- Setgid fixes the group, not the mode. If files come out as 644, the creator's umask is 022; set it to 002 so they come out as 664.
- How do I remove the setgid bit from a directory?
- chmod g-s dir. A plain chmod 775 dir leaves the bit set on GNU systems; chmod 00775 dir clears it.
Last reviewed by Arielton Oberek.