Linux Command Reference ยท Special Files and Directories
The /etc/group file
Reference for /etc/group: the four fields, how supplementary group membership works, GIDs, the relation to /etc/passwd and how to inspect groups safely.
/etc/group lists the local groups of the system and who belongs to them. Every file has an owning group, and a process carries a primary group plus any number of supplementary groups; this file is where the names and the supplementary memberships come from.
Each line has four colon-separated fields. The primary group of a user is not listed here: it is the numeric GID in the user's /etc/passwd line. This file only adds the extra members. Use groupadd, usermod -aG and gpasswd to change it, and getent group to read it, because the answer may also come from LDAP or SSSD.
groupname:password:GID:member1,member2,...
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
| Field | Description |
|---|---|
| group name | The name shown by ls -l and id. Up to 32 characters is the safe limit. |
| password | Almost always x, meaning the group password (rarely used) is in /etc/gshadow. Empty means no password. |
| GID | Numeric group ID. Systems usually reserve 0-999 for system groups and start normal groups at 1000. |
| members | Comma-separated login names without spaces. May be empty. |
Edge cases: a user whose primary group is dev is not required to appear in the dev members list. A name in the member list that does not exist in /etc/passwd is ignored. Two groups may share a GID, but this confuses tools and is best avoided.
Usage notes
- Changes need a new login.
usermod -aG docker alicedoes not affect shells that are already running; the user logs in again, or startsnewgrp dockerorsu - alice. - Always use
-awithusermod -G. Without-athe user is removed from every group not in the list. idandgroupsshow the groups of a running process;getent group NAMEshows what the database says.- Group-owned directories with the setgid bit (
chmod g+s) make new files inherit the directory's group, the usual way to build a shared project folder. See file permissions. - Editing by hand: use
vigr, which locks the file. A syntax error here can break logins. - Special groups:
sudoorwheelgrants administrator rights through the sudoers policy;dockeris effectively root-equivalent access. - Group names and GIDs should be the same across machines that share NFS storage.