How can I view what groups a user is in?

What are some different ways to view what groups a user is in?


If you want to find out which groups a specific user is a member of, you have many choices.

First

Issue id USERNAME command. Groups are listed after groups=.

$ id USERNAME
uid=1000(USERNAME) gid=1000(USERNAME) groups=1000(USERNAME),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare)

Second

groups shows all groups a user is member of. Groups are listed after colon (:).

$ groups USERNAME
USERNAME : USERNAME adm cdrom sudo dip plugdev lxd lpadmin sambashare

Third

The file /etc/group keeps information about groups. First column (separated with colon) is group name and the last column is users that are members of that group.

$ grep USERNAME /etc/group
adm:x:4:syslog,USERNAME
cdrom:x:24:USERNAME
sudo:x:27:USERNAME
dip:x:30:USERNAME
plugdev:x:46:USERNAME
lxd:x:110:USERNAME
USERNAME:x:1000:
lpadmin:x:115:USERNAME
sambashare:x:116:USERNAME