Skip to content

Linux Foundations / Manage a Linux host ยท Step 5 of 50

Lesson: /etc/groupSwitch
โ† Linux Foundations

System administration

/etc/group

Read /etc/group to see which groups exist and who belongs to them.

/etc/group lists the local groups, one per line. It is how you find group numbers and supplementary members.

The four fields

$ grep -E '^(sudo|devs):' /etc/group
sudo:x:27:maya
devs:x:1002:maya,liam
  1. group name
  2. password field, usually just a placeholder such as x
  3. GID
  4. member list, separated by commas with no spaces

Group passwords are rarely used. Where they exist, the protected data lives in /etc/gshadow.

The primary group catch

A user's primary group is set by the GID in /etc/passwd. That user is usually not repeated in the member list of /etc/group:

$ getent passwd maya
maya:x:1000:1000:Maya Rao:/home/maya:/bin/bash
$ getent group maya
maya:x:1000:

The empty fourth field does not mean the group is unused. Maya belongs to it through her primary GID.

For a complete answer about one user, use id:

$ id maya
uid=1000(maya) gid=1000(maya) groups=1000(maya),27(sudo),1002(devs)

Groups with special power

Membership of some groups is as sensitive as having root:

  • sudo or wheel may allow running commands as root, depending on the sudo policy
  • docker, where it exists, effectively grants root on the host

Others grant access to particular resources, such as adm for many logs on Debian and Ubuntu. Review these lists now and then.

Changing groups

Use groupadd, groupmod, groupdel, usermod -aG and gpasswd rather than editing the file. sudo vigr is the safe manual editor.

A change in the file does not update sessions already running. The user must log in again, or can start a shell with the new group using newgrp devs.

Try it

$ id
$ getent group "$(id -gn)"
$ getent group sudo wheel
$ cut -d: -f1,3 /etc/group | head

id -gn prints your primary group's name. Check whether you appear in its member list, and which of sudo or wheel exists on your system. There is more practice in the accounts and access files lab.

Check your understanding

/etc/group

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.