Home  >  Article  >  Operation and Maintenance  >  How to check which group a user belongs to in Linux

How to check which group a user belongs to in Linux

青灯夜游
青灯夜游Original
2021-11-30 16:55:4857948browse

View method: 1. Directly execute the "groups" command to view the groups to which the current user belongs; 2. Execute the "groups username" command to view the groups to which the specified user belongs; 3. Execute "id username" command to view the groups to which the specified user belongs; 4. Execute the "cat /etc/group" command to output the group file information.

How to check which group a user belongs to in Linux

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

Linux method to check which group a user belongs to:

Method 1: Use groups directly to view The group to which the current user belongs

# groups
root

Method 2: Use groups username to view the group to which the specified user belongs

# groups xly
xly : xly

Method 3: Use id username to view the group to which the specified user belongs

# id xly
uid=500(xly) gid=500(xly) groups=500(xly)

Method 4: Directly view the group file, cat /etc/group

# cat /etc/group
root:x:0:
bin:x:1:bin,daemon
daemon:x:2:bin,daemon
sys:x:3:bin,adm
adm:x:4:adm,daemon
tty:x:5:
disk:x:6:
lp:x:7:daemon
mem:x:8:
kmem:x:9:
xly:x:500:

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to check which group a user belongs to in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn