How To Tell What Group Unix User Is In

Have been getting this question asked a lot in the search engine queries for Unix Tutorial lately, and realised in all this time I haven’t created a separate page for the groups command – one of the most basic yet most useful Unix commands ever!

groups Command in Unix

Just like most of Unix/Linux commands, groups does exactly what it says: it shows you a list of Unix groups. Specifically, it shows you groups that your own user belongs to, or lists groups of any other user you specify.

In simplest form, you simply type groups without any parameters:

greys@s2:~ $ groups
greys libvirt

On this s2 server, I’m a member of my own group called greys and also belong to libvirt group which lets me manage kvm virtualization.

Of course, you can specify your own user implicitly as well.

This is what groups I’m in on MacOS:

greys@maverick:~ $ groups greys
 staff com.apple.sharepoint.group.1 everyone localaccounts _appserverusr admin _appserveradm _lpadmin com.apple.sharepoint.group.2 com.apple.sharepoint.group.3 _appstore _lpoperator _developer _analyticsusers com.apple.access_ftp com.apple.access_screensharing com.apple.access_ssh

groups is a basic Unix command

I’ve added groups to the Basic Unix Commands page and also created it a page today: groups command. Can’t believe this truly deserving Unix command escaped the chance to be in the Basic Commands hall of fame for so long!

Other Ways To List User Groups

I’ve actually taken the time ot refresh a really old but great post of mine today: 3 Ways to List Groups for a User in Linux – go read and and let me know what you think. It talks about using id command (quite basic) and getent command (far more advanced) for listing groups.

See Also




List Groups A User Belongs To In Unix

Still seeing this request quite frequently in my website logs, I thought I’d expand the topic a bit more, given the fact that I’ve somehow left out the most obvious way to confirm the group membership for a Unix user.

Group membership in Unix

Every Unix-like OS is bound to have a group command, which is aimed to help you confirm Unix group membership for any user known to your system.

The easiest it to run it and specify a username in command line. The result is a list of Unix groups:

ubuntu$ groups greys
greys : admin www-data

If you’re looking at confirming the membership for a few users, you can specify usernames in the same command line:

ubuntu$ groups greys root
greys : admin www-data
root : root

There you go – hopefully this satisfies your interest. Good luck with Unix experiments!

See also: