breakitdown

chmod 2775: setgid directory (rwxrwsr-x)

Answer

chmod 2775 is 775 plus the setgid bit (the leading 2). On a directory, setgid makes every file and subdirectory created inside it belong to the directory's group instead of the creator's primary group. It is the standard setup for a directory a team edits together.

Try

chmod 2775 = rwxrwsr-x: owner full access, group full access, others read and execute, plus setgid.

Read 4Write 2Execute 1Digit
Owner (user)7
Group7
Others5
Special2
  1. 7
    Owner (user): 7 = 4 read + 2 write + 1 execute
  2. 7
    Group: 7 = 4 read + 2 write + 1 execute
  3. 5
    Others: 5 = 4 read + 1 execute
  4. 2
    Special bits: 2 setgid: a program runs with its group's rights; on a directory, new files inherit the directory's group

On a file

  • Owner (user) read it, change it and run it as a program
  • Group read it, change it and run it as a program
  • Others read it and run it as a program

On a directory

  • Owner (user) list the names inside, enter it and open files by name, create and rename and delete entries
  • Group list the names inside, enter it and open files by name, create and rename and delete entries
  • Others list the names inside and enter it and open files by name

chmod 2775 filechmod u=rwx,g=rwxs,o=rx filels -l → -rwxrwsr-x

What to know

Typical setup: groupadd devs, add the users, then chgrp devs /srv/project and chmod 2775 /srv/project. New files get group devs, and new subdirectories get the group and the setgid bit too, so the behavior continues down the tree.

Setgid fixes the group, not the permission bits. Whether teammates can edit a new file still depends on the creator's umask: under 002 new files are 664 and group-writable; under 022 they are 644 and only readable by the group. Use umask 002 for team members, or a default ACL (setfacl -d -m g::rwX).

Where it fits

Gotchas

Related explainers

← chmod calculator