Users

The groups command

Shows which groups a user belongs to. With no arguments, it shows the groups of the current session; with a name, the ones listed in the system database.

Syntax

groups [usuario...]Try it in the terminal →

Most useful options

--helpShows the help and exits
--versionShows the coreutils version and exits

Copy-ready examples

$ groupsyour groups in the current session.

Example output

miguel adm cdrom sudo dip plugdev lpadmin
$ groups miguelthe groups of miguel according to the system. The first one is his primary group, after the colon.

Example output

miguel : miguel adm cdrom sudo dip plugdev lpadmin
$ groups www-datawhich groups the web server account belongs to, to see in which folders it can write.
$ getent group sudothe full line of the sudo group: its number (GID) and its members.

Example output

sudo:x:27:miguel,ana
$ sudo usermod -aG docker miguel && newgrp dockeradds miguel to the docker group and opens a shell that already has that group active.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
groups: 'nosuchuser': no such userThe name does not exist as a user on the system. It may be misspelled or actually be a group name.Check the name with getent passwd or with id name.
groups: cannot find name for group ID 1005The process has a GID with no name in /etc/group, for example after deleting a group while the session was open.Log out and log back in. To see the numbers, use id -G.

Typical mistakes

  • groups with no arguments shows the groups of the current session, not the ones in the database: after a usermod, log out or use newgrp.
  • usermod -G without -a replaces the whole group list. Always use usermod -aG to add.

Differences from similar commands

  • id: shows user, UID, primary group and all groups with their numbers. groups only shows the names.
  • getent: shows the full line of a group in the system database, with its GID and its members.
  • usermod: changes group membership, with -aG. groups only reads it.

Security

Being a member of sudo or docker is, in practice, the same as having administrator power: docker gives access to the machine filesystem. Check who belongs to those groups with getent group.

Related commands

FAQ

Why does a group I just added not appear?

Because each process keeps the group list it was created with. Log out and back in, or use newgrp. By contrast, groups name shows it at once, because it reads the database.

How do I see who belongs to a group?

With getent group name: the last field lists the members. Users who have that group as their primary group do not appear there, because their primary group is stored in /etc/passwd.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course