Group-Based Privilege and Inheritance
Similar to SUID, the SGID (Set Group ID) bit changes the effective group ID of a running process or the group ownership of newly created files, depending on whether it's set on a file or a directory.
SGID on executable files: When set on an executable, the process runs with the file's group privileges instead of the user's primary group. /usr/bin/wall is a good example — owned by root but with SGID set for group tty, shown as -rwxr-sr-x (the s in the group execute position). That's how wall can write to terminal devices owned by the tty group without needing full root privileges.
SGID on directories (more common and more important):
When set on a directory, any files created inside inherit the directory's group instead of the creator's primary group. This is extremely useful for shared project directories where multiple users need to collaborate: a directory owned by group developers with SGID set produces new files owned by developers regardless of the creating user's own primary group. Without SGID, a file created by alice (whose primary group is alice) would come out owned by alice:alice, and other developers without explicit access to that specific file couldn't write to it. With SGID, the group is automatically set to developers, making the file accessible to the whole team from the moment it's created.
SGID is set symbolically (chmod g+s) or as a leading 2 in four-digit octal (chmod 2775), and appears as an s in the group's execute position of the permission string — a shared directory with SGID set typically shows drwxrwsr-x.
Key Point: SGID on directories is essential for team collaboration in shared filesystems. Without it, files created by different team members would have different group ownership, leading to permission conflicts where one developer can't write to another's files. Always use SGID on shared project directories, Git repositories, and collaborative workspaces. Combine with
umask 002(so new files are group-writable) to create a fully collaborative environment.