Pcornel
Linux · Permissions & Ownership

SGID

Cheat sheet · https://pcornel.dk/topic.php?topic=2709

Back to the Topic

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.

Remember

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.

First 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

Verify in this order

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

Where it usually breaks

First mismatch in identity/group resolution → Unix mode/ACL/capability → mount/sandbox constraint → SELinux/AppArmor policy → credential/TLS trust → protected operation; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2709

Confirmation

Confirm action

Continue?