How to check which group the specify user belongs to

In our daily operation server, we not only need to understand the Linux file permissions, how to change the users and user groups to which the files belong.

At this time, we often need to see which group the specified user belongs to.

Now, let’s take a look at several ways to view the groups:

view current login user

  • linux users command– list current users.
➜  ~ users
  • linux w command — Show who is logged on and what they are doing.
➜  ~ w
 17:30:06 up  8:46,  2 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
ylspirit :0       :0               Fri23   ?xdm?   3:19   0.00s /usr/lib/gdm3/gdm-x-session --run-script env 
ylspirit pts/1    17:04    1.00s  0.93s  0.00s w

  • linux who command — show who is logged on
➜  ~ who
ylspirit :0           2019-11-08 23:10 (:0)
ylspirit pts/1        2019-11-09 17:04 (

View the current login user’s group

  • linux groups command — show group memberships
➜  ~ groups 
staff everyone localaccounts _appserverusr admin _appserveradm _lpadmin _appstore _lpoperator _developer _analyticsusers

View the group to which the specified user belongs

  • use linux groups command
➜  ~ groups mail
mail : mail
  • use linux id command

id – print real and effective user and group IDs

➜  ~ id mail
uid=8(mail) gid=8(mail) groups=8(mail)
  • view /etc/passwd file ( The /etc/passwd file contains the linux system content list of all users)
➜ cat /etc/passwd

  • View /etc/group file
➜  ~ cat /etc/group | grep mail

More about Linux commands: Linux Commands Tutorial

Add a Comment

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