≡ Menu

Linux: Show The Groups a User Is In

How do I find out what groups I belong to under Linux operating systems?

/etc/group is a text file which defines the groups on the system. You can use the groups command to display group memberships for any user using the following syntax.

groups userName-Here


pen 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.

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

How Do I Find Out My Primary Group Membership?

Type the following command:
$ getent group userName
$ getent group vivek

Sample outputs:


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

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 6 comments… add one }
  • Georg February 17, 2014, 2:26 pm

    what I was looking for — thanks!

  • glonner22 June 13, 2014, 9:04 pm

    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 February 24, 2015, 1:15 pm

    which command used to list out only groups?

    • 73mp74710n October 29, 2015, 9:40 pm

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

  • Benjamin Bach August 12, 2015, 5:40 pm

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

  • Kevin Joyce September 9, 2016, 11:38 am

    ‘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
    [root@rugxacxapelo home]# getent passwd user100
    [root@rugxacxapelo home]# id -gn user100

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , , , , , , , ,