CentOS 7.x Get members of OS user group or see groups that a user belongs to

From Notes_Wiki
Revision as of 10:23, 26 January 2019 by Saurabh (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<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 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


<yambe:breadcrumb self="Get members of OS user group or see groups that a user belongs to">CentOS_7.x_troubleshooting|Troubleshooting</yambe:breadcrumb>