How to find out what group a given user has?

2019-01-12 18:53发布

In Unix/Linux, how do you find out what group a given user is in via command line?

4条回答
Fickle 薄情
2楼-- · 2019-01-12 19:24

On Linux/OS X/Unix to display the groups to which you (or the optionally specified user) belong, use:

id -Gn [user]

which is equivalent to groups [user] utility which has been obsoleted on Unix.

On OS X/Unix, the command id -p [user] is suggested for normal interactive.

Explanation on the parameters:

-G, --groups - print all group IDs

-n, --name - print a name instead of a number, for -ugG

-p - Make the output human-readable.

查看更多
孤傲高冷的网名
3楼-- · 2019-01-12 19:30

or just study /etc/groups (ok this does probably not work if it uses pam with ldap)

查看更多
贪生不怕死
4楼-- · 2019-01-12 19:32
groups

or

groups user
查看更多
祖国的老花朵
5楼-- · 2019-01-12 19:39

This one shows the user's uid as well as all the groups (with their gids) they belong to

id userid
查看更多
登录 后发表回答