Site icon LinuxCommands.site

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

➜  ~ users
ylspirit
➜  ~ 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    192.168.159.1    17:04    1.00s  0.93s  0.00s w

➜  ~ who
ylspirit :0           2019-11-08 23:10 (:0)
ylspirit pts/1        2019-11-09 17:04 (192.168.159.1)

View the current login user’s group

➜  ~ groups 
staff everyone localaccounts _appserverusr admin _appserveradm _lpadmin com.apple.sharepoint.group.1 _appstore _lpoperator _developer _analyticsusers com.apple.access_ftp com.apple.access_screensharing com.apple.access_ssh com.apple.access_remote_ae

View the group to which the specified user belongs

➜  ~ groups mail
mail : mail

id – print real and effective user and group IDs

➜  ~ id mail
uid=8(mail) gid=8(mail) groups=8(mail)
➜ cat /etc/passwd

➜  ~ cat /etc/group | grep mail
mail:x:8:

More about Linux commands: Linux Commands Tutorial

Exit mobile version