What it does
groups prints the group names of the current process, or of the users you name. It is the same as id -Gn. The first name is the primary group.
How to write it
groups [OPTION]... [USER]...Options 3
Most used
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1My groups
groups student wheelThe first is the primary group.
2Groups of other users
groups lisa omar lisa : lisa webadmins omar : omar wheel webadminsWith names, each line starts with the user.
3After adding a group
usermod -aG webadmins student groups; groups student student wheel student : student wheel webadminsThe shell gets the new group only after a new login.
4Check admin rights quickly
wheel = sudo on RHEL.
5Count the groups of a user
groups lisa | wc -wThe output includes the name and the colon for a named user.
6Use it in a script for many users
for u in anna bob carol; do groups "$u"; doneFast check after a lab.
7Compare with id
id -Gn lisaSame names, no "lisa :" before them.
8Check a group for a shared folder
groups | grep -w salesNeeded to write in a folder owned by group sales.
9Check the groups of a service user
groups apache apache : apacheService accounts should have as few groups as possible.
10Find members of the docker or wheel group (audit)
getent group wheelgroupsshows per user;getent groupshows per group.
Nothing matches this filter.
Exit codes
0 :: Done. 1 :: A user does not exist.