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.
- What’s the meaning of storying group info into
/etc/passwd
, and/etc/group
respectively? - Why
adduser
only update thegroup
file? - How to add group to the
passwd
file via command? - Why does
groups
return group info frompasswd
file, but notgroup
file?
Thanks.
Advertisement
Answer
- 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
. - see 1.
- That’s impossible, but you can change a primary group with
usermod -g
- 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 thenewgrp
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.