Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

SGID

Direct answer

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.

When to use this

Use it for shared project directories where all files must belong to one group.

First 30 seconds

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.

Operational verification

directory with SGID → user creates a file → file group = directory group → group members can access it

Evidence · next step

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
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it for shared project directories where all files must belong to one group.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 references

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.

observation · 1
Key points

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.

Key checks
  • ls -l <path> — owner, group and mode
  • stat -c '%A %a %U:%G' <path> — symbolic and numeric mode with owner
  • namei -l <path> — permissions of every directory on the path
  • id <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 setgidWith setgid
alice's new file gets group aliceThe new file gets the directory's group, reports
Team members can't edit each other's filesThey can, given group-write permissions
New subdirectories need fixing by handSubdirectories inherit setgid automatically

Setting up a shared directory

StepCommand
Group and directorygroupadd reports; mkdir /srv/reports
Ownershipchgrp reports /srv/reports
Mode with setgidchmod 2770 /srv/reports
Group-writable new filesUsers 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

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%
Technical changelog & impact

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.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

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.

Aliases that resolve here
setgid linuxsgid bitshared directory sgidset group id
Embedded reference data

Quick lookup tables

SGID operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for SGID.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateSGID 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 verificationPin 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 chaininode type + group GID + SGID bit → create or exec operation → inheritance/credential transition → resulting child/process GID → DAC/ACL evaluation → workload resultTrace requested/configured state through effective state to the observed workload result.
Failure boundarySGID 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 evidenceCorrelated 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 resultUse this observation only for the specific claim it actually supports.
Evidence limitIt 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 checkContinue 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 boundarySGID
Topic pathPermissions & Ownership → SGID
Runtime stateSGID 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 chaininode 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 boundarySGID 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 ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?