Frequently Asked Question
What does setgid do on a file versus on a directory?
On an executable file, the setgid bit (octal 2000, displayed as s in the
group's execute position) is the group analogue of setuid: the resulting process
runs with the file's group as its effective GID instead of the invoker's. This is
how games used to write to a shared scoreboard owned by a games group, or how a
mail program might be granted write access to /var/spool/mail through a mail
group without needing full root privileges.
On a directory, setgid has a completely different and much more useful meaning:
files created inside the directory inherit the directory's group rather than the
creator's primary group, and new subdirectories themselves keep the setgid bit
set. That is exactly what you want for a shared project tree, chmod 2775 /srv/project; chgrp developers /srv/project makes everything underneath belong
to the developers group automatically, so any team member can edit anyone
else's files (combined with a group-writable umask). It is the standard recipe
for genuinely shared directories on Linux.