Setgid directory
On Linux, a setgid directory gives newly created children its group ownership and passes the set-group-ID bit to newly created subdirectories.
Ownership: directory S_ISGID (02000) gives new children the parent's group; new subdirectories also inherit that bit. This differs from credential changes when executing a setgid program. [1] [2]
Permissions: group inheritance does not itself grant group write. For regular files created with open()/creat() and directories created with mkdir(), with no parent default ACL, requested_mode & ~umask & 0777 gives ordinary permission bits. A default ACL instead initializes an access ACL constrained by the requested mode. [3] [4]
Calculated example: assume successful creation under a setgid parent, no default ACL and umask 0027. A regular-file request for 0666 yields 0640; a subdirectory request for 0777 yields 0750 plus inherited 02000, conventionally 2750. Both receive the parent's group; neither is group-writable. These are derived examples, not new native observations or complete st_mode values. [3] [2]
Filesystem scope: supporting filesystems can use grpid/bsdgroups to inherit the parent group without parent S_ISGID. With nogrpid and no parent setgid bit, Linux uses the process's filesystem GID. A child's group alone does not identify the inheritance rule. [5]
Recovery: directory group ownership and setgid state are separate from access and default ACLs. Setting this bit on the directory alone does not retroactively change existing children's groups or permissions. [1] [4]
Relations
Limitations
- Linux directory semantics are not a universal ACL or filesystem contract.
- Group inheritance is not an authorization test and does not imply group write permission.
Citations
- Linux man-pages: inode(7), S_ISGID on directories and executables
- Linux man-pages: mkdir(2), group ownership and setgid inheritance
- Linux man-pages: open(2), O_CREAT mode and group ownership
- Linux ACL project: acl(5), object creation and permission classes
- Linux man-pages: chown(2), new-file group ownership and mount policy
Sources & caveats
- Primary-source synthesis with explicitly calculated permission examples. No new native permission, restore or security experiment was performed.
- Human context: https://hesela.com/analyses/posix-acl-restore-permissions/
- Verifying future child creation as well as restored objects is an engineering inference. Identity mapping and destination filesystem behavior need separate acceptance.