Linux Show The Groups a User Is In

See all GNU/Linux related FAQ
How do I find out what groups I belong to under Linux operating systems? How do I display the groups a Linux user belongs to?

The /etc/group is a text file which defines the groups on the Linux system. You can use the groups command to display group memberships for any user using the following syntax.
$ groups
$ groups {user-Name-Here}

Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux terminal
Category User Information
OS compatibility AlmaLinux Alpine Amazon Linux Arch CentOS Debian Fedora Linux Mint Mint openSUSE Pop!_OS RHEL Rocky Slackware Stream SUSE Ubuntu
Est. reading time 2 minutes

Examples about showing the groups a user belongs to in Linux

Open a command-line terminal (select Applications > Accessories > Terminal), and then type:
$ groups
Sample outputs:

vivek cdrom floppy audio dip video plugdev netdev bluetooth scanner

You are part of all of the above groups. To find group memebership for root user, enter:
$ groups root
Sample outputs:

root : root

Please note that (from the groups man page):

Primary and supplementary groups for a process are normally inherited from its parent and are usually unchanged since login. This means that if you change the group database after logging in, groups will not reflect your changes within your existing login session. Running `groups’ with a list of users causes the user and group database to be consulted afresh, and so will give a different result.

Linux Show The Groups a User Is In Using the id command

You can also use the id command as follows to get the same information:
$ id -Gn
$ id -Gn userName
$ id -Gn vivek

List of groups for the ‘vivek’ user:

vivek adm cdrom sudo dip plugdev lpadmin lxd sambashare sales

Using the /etc/group file

Use the grep command or egrep command to query /etc/group file. For instance:
$ grep -w vivek /etc/group

Common commands to list the groups a user belongs to in Linux

Click to enlarge this image

Understanding group membership in Linux

There are two types of groups in Linux.

  1. The primary group for a user is the first group listed (using “groups” or “id“) and is considered their primary group.
  2. Secondary groups refer to any additional groups that a user belongs to, apart from their primary group.

How do I find out my primary group membership in Linux?

Type the following getent command as follows:
$ getent group {userNameHere}
$ getent group vivek

Sample outputs indicating that ‘vivek’ user’s primary group is ‘vivek’:

vivek:x:1000:

In this example, user vivek has group id # 1000 and has group name vivek for primary group membership.

Summing up

You learned the most common commands to list the groups a user belongs to in Linux:

  1. The groups command.
  2. The id command.
  3. Examining the /etc/group file using the grep command.
  4. The getent command.

Read their manual pages using the help command or man command for more information. For instance:
$ man id
$ groups --help

See also

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

6 comments… add one
  • Georg Feb 17, 2014 @ 14:26

    what I was looking for — thanks!

  • glonner22 Jun 13, 2014 @ 21:04

    I added a user to a group, and then I type the groups command, but the addition doesn’t show up in that list. When I look at the groups file, the user name is in fact listed under that group. Any ideas as to why that would be?

  • Bhanu priya Feb 24, 2015 @ 13:15

    which command used to list out only groups?

    • 73mp74710n Oct 29, 2015 @ 21:40

      to list out only the groups this is what you will do
      awk -F : ‘{print $1}’ /etc/gshadow

  • Benjamin Bach Aug 12, 2015 @ 17:40

    “id -gn username” will show only the primary group!

  • Kevin Joyce Sep 9, 2016 @ 11:38

    ‘gentent group username’ does not show the primary group. It shows the group entry in the group database. You’d have to check ‘getent passwd username’ to cross-reference.


    [root@rugxacxapelo home]# getent group user100
    user100:x:1001:
    [root@rugxacxapelo home]# getent passwd user100
    user100:x:1001:1002::/home/user100:/bin/bash
    [root@rugxacxapelo home]# id -gn user100
    user200

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.