Linux/UNIX: Find Which Groups Do I Belong To

by on January 4, 2007 · 1 comment· LAST UPDATED January 25, 2014

in , ,

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:
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
RequirementsNone
Estimated completion time1m
  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:

vivek

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
Output:

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
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 1 comment… read it below or add one }

1 saeed March 15, 2013 at 7:31 am

hi,
I am saeed from Iran I wanna ask you a question:
if a person haven,t access to Internet.how can I join these groups?

Reply

Leave a Comment

Tagged as:

Previous Faq:

Next Faq: