Linux 命令“getent group”没有返回某些组的用户?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17107119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 23:13:23  来源:igfitidea点击:

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

linux

提问by Harinder

I am using getent groupcommand to get the groupsalong with there usernames in linux. But it is not showing any usernamesfor some groupswhich i know exist.

我使用getent group命令来获取groups与那里的用户名一起linux。但是usernames对于groups我知道存在的某些内容,它没有显示任何内容。

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.

如您所见,root 组没有用户,bin 组中有 2 个用户。我知道 root 组包含一个用户 root 但它现在在这里显示它。

采纳答案by twalberg

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

您缺少的是每个用户都有一个主要组,该组存储在/etc/passwd(通常在字段 4 中)中,并且可能有一个或多个补充组。只有补充组关联在 中/etc/group,因此,是唯一getent group会显示的关联。为了获取特定用户的整个组列表,您可以使用id -a <user>,但您必须在用户列表上迭代它以获取完整信息转储...

回答by V H

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 将只返回主组名称,而不返回用户所属的子组:

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

To get any instances of adm within getent try:

要在 getent 中获取任何 adm 实例,请尝试:

getent group|grep adm