Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux command 'getent group' not returning users for some groups?

Tags:

linux

I am using getent group command to get the groups along with there usernames in linux. But it is not showing any usernames for some groups which i know exist.

i need this info is there any other way around?

Picking up 1st two results :--

root:x:0: 
bin:x:1:bin,daemon

as you can see there are no users for group root and 2 users in bin group. I know that the root group contains a user root but its now showing it here.

like image 956
Harinder Avatar asked Sep 20 '25 11:09

Harinder


2 Answers

What you are missing is that each user has a primary group, which is stored in /etc/passwd (usually in field 4), and may have one or more supplementary groups. Only the supplementary group associations are in /etc/group, and as a result, are the only ones that getent group will show. In order to get the entire list of groups for a particular user, you can use id -a <user>, but you'll have to iterate that over the list of users to get your full information dump...

like image 81
twalberg Avatar answered Sep 23 '25 02:09

twalberg


Can you please run:

getent group|diff /etc/group - 

and show us the difference in its output,

Since I have run this and I see no difference their both exactly the same

getent will only return the master group name and not the sub groups a user belongs to:

getent group adm
adm:x:4:me,logcheck

To get any instances of adm within getent try:

getent group|grep adm
like image 28
V H Avatar answered Sep 23 '25 00:09

V H