When adding user like this :
sudo adduser someuser --ingroup sudo
Added user can use
sudo but he is not in
/etc/group sudo nor in
So how does it work ?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
adduser command sets the user's primary group to
By default, each user in Debian GNU/Linux is given a corresponding group with the same name. [ ... ] Users' primary groups can also be overridden from the command line with the --gid or --ingroup options to set the group by id or name, respectively. [ ... ] --ingroup GROUP Add the new user to GROUP instead of a usergroup or the default group defined by USERS_GID in the configuration file. This affects the users primary group. To add additional groups, see the add_extra_groups option
The primary group normally has the same name and ID as the user. It is not stored in
/etc/group but in
/etc/passwd, like this:
:-separated field contains the GID (group ID) of the user's primary group.
/etc/group contains a list of all groups and associates users that have this group as additional (not primary) group, like this:
The distinction between primary and additional groups is also visible in the output of the
id command (formatting by me):
$ id uid=1000(bytecommander) gid=1000(bytecommander) groups=1000(bytecommander),27(sudo)
What is important for the use of
sudo is only membership in the
sudo group, it does not distinguish primary and secondary membership. The responsible configuration line can be found in
/etc/sudoers and looks like this:
%sudo ALL=(ALL:ALL) ALL
This line grants all members of the
sudo group automatically full permissions to run any command as any user, without having to specify each user manually.
--ingroup option of
adduser changes/adds the Primary group of the added user, and the primary group of a user is stored in the
/etc/passwd file, in the
: separated fourth field, as numeric GID.
sudo is reading the
/etc/passwd file, and finding that the user
someuser has the primary group
sudo, so the
sudo commands are working perfectly.
sudo group entry still would not show the membership, because
/etc/group only stores the secondary group membership, not primary.