Anatomy of /etc/group, /etc/gshadow, GIDs, Primary vs Supplementary Groups & the UPG Model
Managing file permissions on a per-user basis in an enterprise environment containing hundreds of developers, database administrators, and automated services is completely unscalable. Linux solves this problem through Groups. A Group is an administrative entity that bundles multiple user accounts together so they can share access to common directories, files, devices, and administrative privileges.
In Linux, a user account interacts with two distinct categories of groups:
| Group Type | Configured In | Operational Purpose & Behavior |
|---|---|---|
| Primary Group | /etc/passwd (Field 4: GID) |
Every user has exactly one primary group. When a user creates a new file or directory, the Linux kernel automatically stamps that file with the user's primary GID. |
| Supplementary (Secondary) Groups | /etc/group (Field 4: Member List) |
A user can belong to multiple secondary groups (e.g. sudo, docker, www-data, developers). These memberships grant read, write, or execute permissions to files owned by those groups. |
Traditional Unix systems assigned all normal users to a generic primary group such as users (GID 100). This created severe security hazards: if a user gave group-write access to a shared project folder, every other user on the system could edit or delete their files.
Modern Linux distributions (pioneered by Red Hat and adopted across Debian/Ubuntu) implement the User Private Group (UPG) scheme. Under UPG:
useradd student), the system automatically creates a matching group with the identical name and identical numeric ID (e.g. group student with GID 1000).umask 002 or 022) without exposing files to other users.devteam) and add members as supplementary users.The /etc/group file defines all existing groups on the machine. Like /etc/passwd, it is a world-readable text file (permissions 644) consisting of 4 colon-delimited fields:
devops:x:1005:alice,bob,carol,student
| Field # | Field Name | Description |
|---|---|---|
| 1 | Group Name | Unique name of the group (lowercase alphanumeric string). |
| 2 | Password Placeholder | Contains an x, indicating that encrypted group passwords are kept in /etc/gshadow. |
| 3 | Group ID (GID) | Unique positive integer identifying the group to the kernel.
• GID 0: root
• GID 1 – 999: System service groups (e.g. daemon, adm, sudo, docker)
• GID 1000+: Regular user private and collaboration groups
|
| 4 | Member List | Comma-separated list of usernames who belong to this group as supplementary members. Notice: Users whose primary group matches this GID are NOT listed here (to avoid redundancy). |
To enable group administrators and group passwords without exposing hashes, modern Linux systems maintain /etc/gshadow (readable only by root, mode 640). Its 4 fields are:
devops:$6$hZ4...:admin_user:alice,bob,carol,student
/etc/group.! if disabled).gpasswd without root privileges.Linux provides several CLI tools to inspect group identities:
# 1. View all groups the current user belongs to
groups
# 2. View groups for a specific user account
groups www-data
# 3. View numeric UID, primary GID, and supplementary GIDs
id student
# Output: uid=1000(student) gid=1000(student) groups=1000(student),27(sudo),1005(devops)
# 4. Query group details using the Name Service Switch (NSS)
getent group devops
If a developer is collaborating in a directory owned by group devops, files they create will ordinarily belong to their private primary group (student). Using newgrp, the user switches their active primary group for the current subshell:
# Switch primary group to 'devops'
newgrp devops
# Verify active primary group has changed:
id
# Output: uid=1000(student) gid=1005(devops) groups=...
# Files created now will be owned by devops:
touch project_spec.md
ls -l project_spec.md
# -rw-r--r-- 1 student devops 0 Nov 2 11:00 project_spec.md
# Exit subshell to return to standard primary group:
exit
Terminal Lab Exercise: Open your terminal and execute these commands to explore group configurations:
# Step 1: Check your current user's primary and secondary groups
id -g # Displays numeric primary GID
id -gn # Displays text name of primary group
id -G # Displays all group IDs (primary + supplementary)
id -Gn # Displays all group names
# Step 2: Search for administrative groups (sudo, wheel, or adm)
grep -E "(sudo|wheel|adm):" /etc/group
# Step 3: Count total groups defined on your system
wc -l /etc/group
/etc/passwd, which is automatically assigned as the group owner for any new files created by the user. A user can belong to multiple supplementary groups, defined in /etc/group, which grant access permissions to shared files and system resources.
x), 3. Numeric Group ID (GID), 4. Comma-separated list of supplementary usernames.
/etc/passwd. Listing the user in /etc/group would be redundant. The 4th field of /etc/group only lists supplementary group members.
/etc/gshadow contains encrypted group passwords and designates group administrators who are authorized to add or remove group members using gpasswd without needing root access.
newgrp switches the user's active primary group in the current subshell session to another group of which they are a member, ensuring newly created files inherit the specified group ownership.
sudo. On Red Hat, CentOS, Fedora, and AlmaLinux, the administrative group is wheel.
getent group [groupname]. The getent utility queries the Name Service Switch (NSS), pulling records from local files (/etc/group) as well as network identity systems (LDAP, Active Directory, SSSD).
/etc/passwd). However, they can belong to dozens of supplementary groups.
newgrp) for the new group credentials to activate.
find command with the -group option: find /var/www -group developers.
docker group allows them to execute docker commands and interact with the Docker UNIX socket (/var/run/docker.sock) without prefixing every command with sudo. Note: this grants equivalent root power!
grpck (Group Check) command audits /etc/group and /etc/gshadow for syntax errors, missing fields, duplicate group names, or invalid members.