Linux/UNIX: Find Which Groups Do I Belong To

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

See also

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

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

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts