Difference between revisions of "CentOS 7.x Get members of OS user group or see groups that a user belongs to"
From Notes_Wiki
(Created page with "<yambe:breadcrumb self="Get members of OS user group or see groups that a user belongs to">CentOS_7.x_troubleshooting|Troubleshooting</yambe:breadcrumb> =CentOS 7.x Get member...") |
m |
||
Line 1: | Line 1: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 7.x]] > [[CentOS 7.x troubleshooting|Troubleshooting]] > [[CentOS 7.x Get members of OS user group or see groups that a user belongs to]] | |||
==List all users and their corresponding groups== | ==List all users and their corresponding groups== | ||
Line 26: | Line 25: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 7.x]] > [[CentOS 7.x troubleshooting|Troubleshooting]] > [[CentOS 7.x Get members of OS user group or see groups that a user belongs to]] |
Latest revision as of 09:05, 25 August 2022
Home > CentOS > CentOS 7.x > Troubleshooting > CentOS 7.x Get members of OS user group or see groups that a user belongs to
List all users and their corresponding groups
In Linux to list all users and groups for which they are member:
cat /etc/passwd | awk -F ':' '{print $1 }' | xargs -n1 groups
In other way round to see which users belong to a particular group we can use above output and grep for groupname. Such as
cat /etc/passwd | awk -F ':' '{print $1 }' | xargs -n1 groups | grep <group1>
Getent information of a group
Please note that genent group might not be sufficient as users primary group information would be in /etc/passwd and wont be shown in this output. For example
getent group root
on CentOS might show group root not having any members. However doing
groups root
will show user root belonging to group root
Home > CentOS > CentOS 7.x > Troubleshooting > CentOS 7.x Get members of OS user group or see groups that a user belongs to