1

The user ldl is exists in the root group, but when I use groups root check it, do not shows the ldl user.

[root@localhost Qiyun02]# usermod -g root ldl
[root@localhost Qiyun02]# groups root
root : root

You see, use groups root list the user, do not shows the ldl.


EDIT

I also tried :

usermod -a -G root ldl

append the user ldl to root group, but still use groups root do not shows the ldl user.

  • 2
    Do you notice that you’re querying two different users? – Jeff Schaller Dec 27 '17 at 2:13
  • 1
    In addition to what @JeffSchaller said, you have to log out and back in to see the effect. – Aaron D. Marasco Dec 27 '17 at 2:35
  • what does getent group root say? BTW, you're using groups wrong. groups USERNAME shows what groups USERNAME is in. i.e. it is not groups GROUPNAME – cas Dec 27 '17 at 3:31
4

The groups command is not for displaying the members of a group. Rather it's for displaying the groups that a user is a member of.

So groups root will show you all the groups that the root user is a member of.

If you have members installed, you can use members root to show you all the users that are in the root group.

Otherwise, you can just use getent group root to see all the users that are in the root group.

Edited to show getent example, because as @cas pointed out, the local group file is not the only source of group information, especially on a networked machine that may be part of an AD domain, or a NIS+ domain, or which may simply be using an alternate authentication database, like ldap, or mysql, or another tool like extrausers (again, thanks to @cas).

  • 3
    use getent rather than grep ... /etc/group. the /etc/group file is NOT the only possible source of group data, just as /etc/passwd is not the only possible source of user data. – cas Dec 27 '17 at 4:10
  • 1
    very good point, @cas – Tim Kennedy Dec 27 '17 at 4:20
  • 2
    that's worth a +1 now. btw, not only useful on networked machines - e.g. there's dozens of NSS modules (e.g. for berkeley db, pgsql, mysql, ldap, and more. There's one called 'extrausers' which I've used several times, allows you to have additional passwd, group, and shadow files). – cas Dec 27 '17 at 4:35
  • 1
    thank you, @cas. I appreciate your contribution to this answer. I'd never heard of extrausers, but I can see many ways it would be useful. – Tim Kennedy Dec 27 '17 at 4:59
  • 2
    i once used extrausers to give static uids and gids to users from an AD domain (not administered by me) where the admins refused to install the unix extensions. I wrote a perl script, run from cron, to recursively query the AD server to build up a list of users and groups (the recursion was needed here because groups can be members of other groups in AD. in unix, only users can be members of groups). Auth was still done via AD but uid, gid, shell, home dir, etc came from the extrausers files. This also sped up ls -l etc because it avoided the need for AD lookups for every uid/gid. – cas Dec 27 '17 at 5:19
0

As Tim Kennedy reminder, the groups do not shows a group's all members.

You can also use the id to check a user's groups, I use root as example:

$ id root
uid=0(root) gid=0(root) group=0(root)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.