/etc/group

Also known as: group file

On this page 7

/etc/group is the plain-text group database of a Linux system: each line defines one local group by its name, password placeholder, numeric group identifier (GID) and list of supplementary members. Together with /etc/passwd and /etc/gshadow, the group file tells the system which groups exist and who belongs to them, which is the basis of group-based permissions in Linux.

When a process opens a file, the kernel compares the file’s group owner with the group IDs attached to the process, and those IDs come from this file at login. Editing /etc/group therefore changes who can read, write or execute group-owned files, directories and devices.

The format of /etc/group entries

Every line in /etc/group has four colon-separated fields, and the file must stay world-readable because ordinary programs such as ls need it to translate GIDs into names. A typical entry is developers:x:1050:alice,bob.

FieldExampleMeaning
Group namedevelopersHuman-readable name, unique on the system
Password fieldxPlaceholder; the real hash, if any, is in /etc/gshadow
Group ID (GID)1050Number stored in file ownership and checked by the kernel
Member listalice,bobComma-separated supplementary members, no spaces
Fields of an /etc/group line

The kernel never reads /etc/group directly; it works only with numeric GIDs. The name exists for people and tools, so renaming a group does not change file access, while changing its GID orphans every file that still carries the old number.

Primary and supplementary group membership

A Linux user has exactly one primary group and any number of supplementary groups, and /etc/group records only part of that picture. The primary group is stored as the fourth field of /etc/passwd, so a user is often a member of a group without appearing in its member list.

Membership typeStored inTypical effect
Primary groupGID field of /etc/passwdDefault group owner of new files
Supplementary groupMember list in /etc/groupExtra access to group-owned resources
Group administrator/etc/gshadowMay add or remove members with gpasswd
Temporary groupSet by newgrp at runtimeChanges the effective group of a shell
Where each kind of membership is recorded

Most distributions follow the user private group scheme: useradd creates a group with the same name as the user and makes it the primary group, which allows a permissive umask of 002 without exposing files to other users.

How /etc/group relates to other account files

The group file is one of several local account databases that the shadow suite keeps consistent. Knowing which file holds which data prevents the most common editing errors.

FileContentsPermissions
/etc/groupGroups, GIDs, supplementary members0644, readable by all
/etc/gshadowGroup password hashes and administrators0640 or 0000, root only
/etc/passwdUsers, UIDs, primary GIDs, shells0644, readable by all
/etc/shadowUser password hashes and aging data0640 or 0000, root only
/etc/login.defsGID ranges and defaults for new groups0644, readable by all
Account files compared

Lookups do not have to stop at the local file. The Name Service Switch configured in /etc/nsswitch.conf can add LDAP, SSSD or systemd-userdb sources, which is why getent group name is the reliable way to query a group, while reading /etc/group with cat shows only local entries.

Managing groups safely

Administrators should change /etc/group with dedicated tools rather than a plain editor, because the tools lock the file, update /etc/gshadow in step and validate the syntax.

  • groupadd creates a group; groupadd -r picks a system GID, usually below 1000 as set by SYS_GID_MAX.
  • usermod -aG appends supplementary groups; omitting -a replaces all existing memberships.
  • gpasswd -a and gpasswd -d add or remove one member without touching others.
  • groupmod renames a group or changes its GID; groupdel removes it.
  • vigr opens the file with locking when manual editing is unavoidable, and grpck checks consistency.

A membership change does not affect sessions that are already running, because supplementary GIDs are copied into the process credentials at login. The user must log out and in again, or start a shell with newgrp, before id shows the new group. Long-running services started by systemd likewise need a restart to pick up new supplementary groups, since their credentials were fixed when the process was launched.

Common mistakes with /etc/group

Errors in the group file usually appear as unexpected permission denials or, worse, silent over-privilege. The table below lists frequent problems and their fixes.

SymptomLikely causeFix
User lost all other groupsusermod -G used without -aRe-add groups with usermod -aG
New group not visible to userSession started before the changeLog in again or use newgrp
Files show a number instead of a groupGroup deleted or GID changedRecreate the GID or run chgrp
Lookup tools behave oddlySyntax error or duplicate entryRun grpck and edit with vigr
Unexpected sudo or Docker accessUser in wheel, sudo or dockerAudit privileged group members
Group file problems and fixes

Membership in groups such as wheel, sudo, adm, disk or docker is effectively administrative privilege, so these entries deserve regular review in any security audit. A useful habit is to compare the output of getent group against an approved list and to record every membership change in the change log, because the group file itself keeps no history of who was added or when.

The simple explanation

Think of /etc/group as the membership list of every club on a Linux computer. Each line names a club, gives it a number, and lists the people who belong to it.

Files and folders can be shared with a club. When someone tries to open a shared file, the computer checks whether that person is in the right club. Adding a name to the list grants access, and removing it takes the access away at the next login.

How it is used in practice

A small web agency runs a shared Linux server where three developers maintain the company website under /srv/site. The administrator runs groupadd webdev, which adds a new group line such as webdev:x:1201: to /etc/group, and then usermod -aG webdev for each developer, so the line becomes webdev:x:1201:anna,marek,lucia.

Next, the administrator runs chgrp -R webdev /srv/site and sets the setgid bit on the directories with chmod 2775, so new files automatically belong to webdev. After logging in again, all three developers can edit each other’s files, while other server accounts can only read them. When Marek leaves the agency, gpasswd -d marek webdev removes his write access without changing any file permissions.