2

Mirror Question: https://unix.stackexchange.com/questions/217300/where-how-is-user-group-information-stored-in-ubuntu. (I'll remove one of them after I got the answer)


Two places possible: /etc/group and /etc/passwd.

If I use command: adduser [username] [groupname], then the user would be added to the group, and the file /etc/group would then be updated.

However, the file /etc/passwd is not updated. if I check which group I belongs to, via groups command, I can only see groups stated in passwd file.. therefore, the user is not added to the group base on this result.


I'm confused.

  1. What's the meaning of storying group info into /etc/passwd, and /etc/group respectively?
  2. Why adduser only update the group file?
  3. How to add group to the passwd file via command?
  4. Why does groups return group info from passwd file, but not group file?

Thanks.

Community
  • 1
  • 1
songyy
  • 4,323
  • 6
  • 41
  • 63

1 Answers1

4
  1. In these traditional text files (there are other ways, e.g. LDAP), your primary group goes to /etc/passwd (it's e.g. used for permissions of files you create), all additional groups go to /etc/group.
  2. see 1.
  3. That's impossible, but you can change a primary group with usermod -g
  4. That's a misinterpretation, groups shows all groups. But a new group is only picked up when you start a new session (new login). You can use the newgrp command, that starts a session with the given group name as your primary group (you must be member of this group) -- as a side effect, it will consult the user database and update your groups list.
  • Thanks, that's really complete answer. One more question: what's the difference between `primary group`, and `normal group`? – songyy Jul 21 '15 at 05:53
  • A running process has *one* group id ... when you start a process, it has your user id and the group id of your primary group. That's why files you create normally have the group id of your primary group. `newgrp` starts a sub-session with a different primary group, I guess by calling `setsid(2)` and `setgid(2)` and then `execv(3)` your shell –  Jul 21 '15 at 05:55
  • Now I get it. Thanks! – songyy Jul 21 '15 at 05:59