Use it for shared project directories where all files must belong to one group.
SGID
SGID (mode 2xxx, s in the group execute position) on a program runs it with the file's group; on a directory, new files inherit the directory's group instead of the creator's primary group.
1. ls -ld <dir> — s in the group position?
2. Set: chgrp <group> <dir> and chmod 2775 <dir>.
3. Existing files: chgrp -R <group> <dir>.
4. Members' umask 002 (or default ACL) so group can write.
5. Create a test file and check its group.
directory with SGID → user creates a file → file group = directory group → group members can access it
For Permissions & Ownership → SGID, continue with the first unproven Topic check: Identify object type, group owner and SGID bit. If that boundary is healthy, advance to the adjacent check: For a directory, create a controlled child and verify inherited GID plus mode/ACL. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
inode type + group GID + SGID bit → create or exec operation → inheritance/credential transition → resulting child/process GID → DAC/ACL evaluation → workload result
Healthy evidence: SGID is applied to the intended file/directory, resulting group identity is verified and the collaborative/exec use case works with minimal rights.
Step 2 Verification and output interpretation Verify boundary
Existing fast checks for this Topic. - Identify object type, group owner and SGID bit.
- For a directory, create a controlled child and verify inherited GID plus mode/ACL.
- For an executable, capture effective group after exec and inspect mount/process constraints.
- Test the intended collaborative or privileged workload separately.
Verification chain. inode type + group GID + SGID bit → create or exec operation → inheritance/credential transition → resulting child/process GID → DAC/ACL evaluation → workload result
Step 3 Commands Verify boundary
chmod g+s /srv/shared
ls -ld /srv/shared # drwxrwsr-x
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: directory SGID is assumed to grant write, existing children are assumed fixed automatically, or executable transition is inferred without checking effective GID.
Step 5 Common mistakes Narrow the fault
- Shared directories without SGID, so files get wrong groups.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
For shared directories combine SGID with group write and a suitable umask (002) or default ACLs, so members can edit each other's files. Existing files are not changed — fix them with chgrp -R.
ls -l <path>— owner, group and modestat -c '%A %a %U:%G' <path>— symbolic and numeric mode with ownernamei -l <path>— permissions of every directory on the pathid <user>— user's groups
ReferenceWhat it is1 section · depth on demand
Core model
Interpret SGID based on object type. For executables, verify post-exec effective group and suppression constraints; for directories, verify actual group inheritance and resulting mode/ACL behavior for newly created children. SGID alone does not grant group write or make every descendant recursively conform.
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
SGID metadata shows configured inheritance/transition intent, not group write access, recursive state or successful workload behavior.
In depth
The set-group-ID bit on files and directories
The setgid bit has different meanings on files and on directories, and the directory meaning is the one administrators use most. The inode(7) manual page describes both:
- On a directory: new files take their group from the directory, not from the creator's primary group, and new subdirectories inherit the setgid bit.
- On an executable: the program runs with the file's group as its effective group.
When the group execute bit is not set, the setgid bit instead indicates mandatory file locking, a historical feature.
Setgid directories for shared work
| Without setgid | With setgid |
|---|---|
alice's new file gets group alice | The new file gets the directory's group, reports |
| Team members can't edit each other's files | They can, given group-write permissions |
| New subdirectories need fixing by hand | Subdirectories inherit setgid automatically |
Setting up a shared directory
| Step | Command |
|---|---|
| Group and directory | groupadd reports; mkdir /srv/reports |
| Ownership | chgrp reports /srv/reports |
| Mode with setgid | chmod 2770 /srv/reports |
| Group-writable new files | Users need umask 002, or a default ACL |
Setgid programs
Some programs use setgid to access a group-owned resource without root. For example, older systems ran wall and write setgid tty, so they could write to terminals. Audit them like SUID files.
host$ sudo chgrp reports /srv/reports && sudo chmod 2770 /srv/reports
host$ ls -ld /srv/reports
drwxrws--- 2 root reports 4096 Nov 28 10:31 /srv/reports
host$ sudo -u alice touch /srv/reports/q4.csv
host$ sudo -u alice mkdir /srv/reports/archive
host$ ls -l /srv/reports
drwxr-sr-x 2 alice reports 4096 Nov 28 10:32 archive
-rw-r--r-- 1 alice reports 0 Nov 28 10:32 q4.csv
host$ sudo setfacl -d -m g:reports:rwX /srv/reports
host$ sudo find / -xdev -perm -2000 -type f -printf '%g %m %p\n' 2>/dev/null
Reading the example
The new file and subdirectory both got the group reports, and the subdirectory inherited the setgid bit (the s in drwxr-sr-x). But with alice's umask 022, the file isn't group-writable. The default ACL added at the end makes new files group-writable regardless of each user's umask.
Documented example, not captured output.
How it works at runtime
SGID is part of Permissions & Ownership → SGID. SGID is the set-group-ID bit with two major Linux filesystem roles: on executable files it can select the file group as effective group at exec, while on directories it commonly causes new entries to inherit the directory group and supports collaborative group ownership.
Topic-specific state model. SGID is the set-group-ID bit with two major Linux filesystem roles: on executable files it can select the file group as effective group at exec, while on directories it commonly causes new entries to inherit the directory group and supports collaborative group ownership.
Technical metadata. Host/container/user-namespace identity, process PID/session/service, identity source/NSS result, username/group names, numeric UID/GID, real/effective/saved/fs credentials where relevant, supplementary groups, sudo invoking/target identity and matched policy, pathname + parent traversal, filesystem/inode, numeric owner/group, object type, octal/symbolic mode, SUID/SGID/sticky bits, access/default ACL entries and mask, mount flags and relevant non-DAC control, requested operation and original workload result.
Interpretation rule. - SGID file semantics ≠ SGID directory semantics.
- Directory SGID ≠ automatic group write permission.
- SGID directory ≠ retroactive ownership change for existing children.
- SGID bit ≠ guaranteed privilege transition when execution constraints suppress it.
Quick reference
SGID on an executable runs it with the file's group; on a directory, new files inherit the directory's group instead of the creator's primary group — ideal for shared project folders.
mkdir /srv/projects
chgrp devops /srv/projects
chmod 2770 /srv/projects
ls -ld /srv/projects # drwxrws---
Combine with umask 002 or default ACLs (setfacl -d -m g:devops:rwX) so group members can also write each other's files.
Limits and how it fails
Primary failure point. SGID metadata shows configured inheritance/transition intent, not group write access, recursive state or successful workload behavior.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. SGID owns set-group-ID semantics. Group membership, umask/default ACL and application collaboration policies remain adjacent concerns.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Permissions & Ownership → SGID. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.kernel.org/doc/man-pages/ · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
SGID operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for SGID.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | SGID is the set-group-ID bit with two major Linux filesystem roles: on executable files it can select the file group as effective group at exec, while on directories it commonly causes new entries to inherit the directory group and supports collaborative group ownership. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin the exact process/session → resolve user/group names to numeric UID/GID through the effective identity stack → capture effective UID/GID + supplementary groups → resolve every required path component and target inode → inspect numeric owner/group + mode + ACL/mask + special bits → capture sudo/privilege transition if present → account for non-DAC controls → repeat the original workload operation. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | inode type + group GID + SGID bit → create or exec operation → inheritance/credential transition → resulting child/process GID → DAC/ACL evaluation → workload result | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | SGID metadata proves configured inheritance/transition intent, not group write access, recursive state or successful workload behavior. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux identity and authorization evidence can establish this proof path: inode type + group GID + SGID bit → create or exec operation → inheritance/credential transition → resulting child/process GID → DAC/ACL evaluation → workload result | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove behavior outside the captured identity source, process credential, filesystem object, DAC/ACL, privilege or workload scope. SGID metadata proves configured inheritance/transition intent, not group write access, recursive state or successful workload behavior. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven boundary: keep the same process/session, resolve numeric identity and groups, inspect each path component plus target ownership/mode/ACL/special bits, capture any privilege transition/non-DAC denial, then repeat the original operation before broadening permissions. | Continue to the next unresolved boundary while preserving the original test condition. |
SGID · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | SGID |
|---|---|
| Topic path | Permissions & Ownership → SGID |
| Runtime state | SGID is the set-group-ID bit with two major Linux filesystem roles: on executable files it can select the file group as effective group at exec, while on directories it commonly causes new entries to inherit the directory group and supports collaborative group ownership. |
| Fast checks | - Identify object type, group owner and SGID bit. - For a directory, create a controlled child and verify inherited GID plus mode/ACL. - For an executable, capture effective group after exec and inspect mount/process constraints. - Test the intended collaborative or privileged workload separately. |
| Verification chain | inode type + group GID + SGID bit → create or exec operation → inheritance/credential transition → resulting child/process GID → DAC/ACL evaluation → workload result Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary. |
| Failure boundary | SGID metadata proves configured inheritance/transition intent, not group write access, recursive state or successful workload behavior. Boundary chain: process/socket namespace → source/rule/FIB → neighbor → netfilter/eBPF/qdisc → virtual/physical device → peer → return → application. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |