I did a usermod
to add the current user user
in a group, but when I run id -Gn
it only shows the main user's group:
[user@computer ~]$ id -Gn
user
But when I specify the user, it works normally:
[user@computer ~]$ id -Gn user
user newgroup
Do you have an idea why it works like it? Am I missing something concerning the groups management in UNIX?
id -Gn user
,id
will perform a group lookup based on/etc/group
. When callingid -Gn
,id
will only lookup groups registered in the current session (that is, for the current user). – John WH Smith Aug 10 '14 at 15:22strace id
, you can see it read information from/etc/group
. – cuonglm Aug 10 '14 at 15:25/etc/group
file is the default way group information is stored. Systems can supplement it with other sources such as YP/NIS and LDAP. Theid
andgetent
commands will query whatever source(s) the system uses. (Likewise for/etc/passwd
and several other databases). – Keith Thompson Aug 10 '14 at 19:15id
reads/etc/group
in either case is not relevant.id
will callgetgroups(3)
, which returns an array ofgid_t
types (integers) for the current session.id
needs to scan the/etc/group
file to retrieve the names for the groups (e.g.100(users)
,10(wheel)
...). When you give a username toid
, it has to open the/etc/passwd
file to get the user ID, then it finds groups that this user belongs to in the/etc/group
file. – sleblanc Aug 10 '14 at 19:21newgrp -
might also be useful. – bishop Aug 10 '14 at 19:54/etc/group
. – JdeBP Jun 22 '20 at 17:48