Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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 

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?

share|improve this question

marked as duplicate by Gilles, jasonwryan, cuonglm, polym, slm Aug 11 '14 at 5:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 7 down vote accepted

That's because your active set of groups is only determined at login. You'll need to logout and login again to pick up the change and see it reflected by id. You can see this another way by issuing cat /proc/$$/status which lists most of your current (session) process states.

share|improve this answer
+1. Just in order to point out the difference: when calling id -Gn user, id will perform a group lookup based on /etc/group. When calling id -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:22
@JohnWHSmith: run strace id, you can see it read information from /etc/group. – cuonglm Aug 10 '14 at 15:25
Thanks all, I just logged out and in and it works now. Thanks for the precisions. – Nautigsam Aug 10 '14 at 15:27
The /etc/group file is the default way group information is stored. Systems can supplement it with other sources such as YP/NIS and LDAP. The id and getent commands will query whatever source(s) the system uses. (Likewise for /etc/passwd and several other databases). – Keith Thompson Aug 10 '14 at 19:15
That id reads /etc/group in either case is not relevant. id will call getgroups(3), which returns an array of gid_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 to id, 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:21

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