Each line in the /etc/group file contains information about one group. Each group entry is divided into four colon-separated fields. Use cat to view its contents.
cat /etc/group
You will see entries for various system groups and user-private groups. For example, the labex group entry might look like this:
labex:x:1000:
Let's break down each field:
labex: Name for this group.
x: Obsolete group password field; this is now a placeholder.
1000: The GID number for this group.
- (empty): A list of users that are members of this group as a secondary group. If this field is empty, it means no additional users are explicitly listed as secondary members of this group (though the primary user
labex is implicitly a member).
Primary Groups and Secondary Groups:
Every user has exactly one primary group. For local users, this group is listed by GID in the /etc/passwd file. The primary group owns files that the user creates. When creating a regular user, a group is often created with the same name as the user, to be the primary group for the user. The user is typically the only member of this User Private Group. This design simplifies file permission management.
Users might also have secondary groups. Membership in secondary groups is stored in the /etc/group file. Users are granted access to files based on whether any of their groups have access, regardless of whether the groups are primary or secondary. For example, if the labex user has a labex primary group and wheel as a secondary group, then that user can read files that any of those two groups can read.
The id command can show all group memberships for a user. Recall the output of id for labex:
uid=1000(labex) gid=1000(labex) groups=1000(labex),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
Here, gid=1000(labex) indicates labex is the primary group. groups=1000(labex),10(wheel) lists all group memberships, showing labex as the primary group and wheel as a secondary group.