Skip to content

Setgid (Set Group ID): Controlling Default Group Ownership

The setgid bit (SGID) ensures that files and directories created within a directory inherit the group ownership of the parent directory, rather than the primary group of the user creating them. This is particularly useful in collaborative environments where multiple users share access to project directories.

Identifying the Setgid Bit

When viewing directory permissions with ls -ld, the setgid bit appears as:

  • s (lowercase) in the group execute field if execute (x) permissions are also set.
  • S (uppercase) in the group execute field if execute (x) permissions are not set.

Examples:

drwxrws--- dir1  # Setgid set with group execute permission
drwxr-S--- dir2  # Setgid set without group execute permission

Setgid Bit Behavior

When the setgid bit is set on a directory:

  • New files inherit the parent directory's group ownership.
  • New directories inherit the parent directory's group ownership and the setgid bit.

For example, assuming a project directory with the setgid bit (/gpfs/scratch/company/project01/):

> ls -ld /gpfs/scratch/company/project01/dir1
drwxrws--- 2 user project01 4096 dir1  # Setgid set

Creating new files or subdirectories:

> touch dir1/newfile
> mkdir dir1/newsubdir
> ls -l dir1
-rw-rw---- 1 user project01    0 newfile
drwxrws--- 2 user project01 4096 newsubdir

Warning

If the setgid bit is not set, new files and directories will inherit the user's primary group, which may lead to permission or quota issues.

Danger

For directories, the setgid bit is beneficial because it ensures group inheritance, but for files, it's usually unnecessary and potentially risky.