You can use the id
command to show the groups a user is in on a Linux system. The basic syntax of the id
command is as follows:
id username
Where username
is the name of the user you want to check.
For example, to show the groups for the user johndoe
, you would run the following command:
id johndoe
This will produce output similar to the following:
uid=1000(johndoe) gid=1000(johndoe) groups=1000(johndoe),4(adm),24(cdrom),27(sudo),46(plugdev)
The output shows the user ID (uid
), the primary group ID (gid
), and the list of group IDs that the user is a member of (groups
). The group IDs are listed in parentheses along with the name of the group (as defined in the /etc/group
file).
You can also use the groups
command to show the groups a user is in, which produces a simplified output that lists only the group names:
groups johndoe
This will produce output similar to the following:
johndoe adm cdrom sudo plugdev