Linux/UNIX: Find Which Groups Do I Belong To

Posted on in Categories , , last updated January 25, 2014

How do I find out in which groups do I belong to on Linux or Unix-like operating systems? How can I find out my group membership so that I can determine access to devices and files on Linux/Unix operating systems?

A user can be in any number of groups apart from his/her default group. Groups are created and managed by root user. You cannot edit or modify your own ownership. However Linux allows you to view in which groups you are by using the groups command. This is useful to find out if you can access:

  1. Directories
  2. Files
  3. Devices
  4. Burn CD/DVD
  5. Backup files
  6. Restart system services
  7. Play music and video and more.

Task: Display or print the groups a user is in

Type the whoami command to display your user ID:
$ whoami
Sample outputs:


See which groups your Linux/Unix user belongs to

Type the groups command to show which groups your Unix or Linux user belongs to:
$ groups
Sample outputs:

vivek dialout cdrom floppy audio video plugdev

So my default group is vivek and I am a member of dialout, cdrom, floppy, audio, video plugdev group. You can also use id command to print both numeric and name based group id:
$ id

uid=1000(vivek) gid=1000(vivek) groups=20(dialout), 24(cdrom), 25(floppy), 29(audio), 44(video), 46(plugdev), 1000(vivek)

The id command is preferred command to list groups a user belongs to On Linux or Unix-like operating systems:
$ groups
$ groups userNameHere
$ id -Gn
$ id -Gn userNameHere

Sample outputs:

Animated gif 01: groups and id command to display groups a user belongs to
Animated gif 01: groups and id command to display groups a user belongs to

See also

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 1 comments/add one below):

1 comment

Leave a Comment