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 /etc/sudoers
So how does it work ?
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 /etc/sudoers
So how does it work ?
The
--ingroup
option ofadduser
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.So
sudo
is reading the/etc/passwd
file, and finding that the usersomeuser
has the primary groupsudo
, so thesudo
commands are working perfectly.Now,
/etc/group
'ssudo
group entry still would not show the membership, because/etc/group
only stores the secondary group membership, not primary.Your
adduser
command sets the user's primary group tosudo
.From
man adduser
: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:The 4th
:
-separated field contains the GID (group ID) of the user's primary group.Now
/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):What is important for the use of
sudo
is only membership in thesudo
group, it does not distinguish primary and secondary membership. The responsible configuration line can be found in/etc/sudoers
and looks like this: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.