Skip to content

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

Which permission bits each class has
WhoRead (4)Write (2)Execute (1)Digit
Owner (u)YesYesYes7
Group (g)YesYesYes7
Others (o)YesNoYes5

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.

What each class can do with a file and with a directory
WhoOn a fileOn a directory
Owner (u)Read, modify and runList, enter, create, delete and rename entries
Group (g)Read, modify and runList, enter, create, delete and rename entries
Others (o)Read and runList, 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

Representations of this mode
Octal2775
Symbolicrwxrwsr-x
ls -l, file-rwxrwsr-x
ls -l, directorydrwxrwsr-x
Equivalent symbolic commandchmod u=rwx,g=rwxs,o=rx
Default umask that creates itNone of the common umasks; set it explicitly with chmod
How Git records a file with it100755 (executable)
Special bitssetgid

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 files

Commands

Set it on one file or directory
sudo chmod 2775 /srv/projects
sudo chmod u=rwx,g=rwxs,o=rx /srv/projects   # same result
Check the result
stat -c '%a %A %n' /srv/projects     # Linux (GNU stat): 2775 drwxrwsr-x
stat -f '%Mp%Lp %Sp %N' /srv/projects   # macOS and BSD

Applying 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.