How to add self to sudoers list?
Solution 1
You need to log in again after adding yourself to a group to get the correct privileges.
To verify with two shells:
alice $ sudo adduser test
alice $ su - test
alice $ sudo adduser test sudo
test $ sudo ls
test is not in the sudoers file. [...]
test $ exit
alice $ su - test
test $ sudo ls
examples.desktop
To clarify, any shells which were opened before the user was added to the sudo
group do not have the new privileges.
Solution 2
There are two different things in action here:
- The sudo user group.
- The /etc/sudoers file.
In some distibutions, the sudoers group is configured in the sudoers file to run everything via sudo.
To add the group you can edit the file by running this as root:
visudo
and adding the following (or un-commenting it):
%sudo ALL=(ALL) ALL
The % sign indicates it's a group name, the first "ALL" is the hosts it can run on, second is the users it can impersonate, the last "ALL is the commands it can run via sudo.
In addition, you probably need to re-login for the new group membership to take effect.
To check active group memberships run:
id
Related videos on Youtube
oshirowanen
Updated on September 18, 2022Comments
-
oshirowanen almost 2 years
I've added myself into the sudoers users list by using the command
root@debian:/home/oshirowanen#adduser oshirowanen sudo
If I try to run that command again,
root@debian:/home/oshirowanen# adduser oshirowanen sudo The user `oshirowanen' is already a member of `sudo'. root@debian:/home/oshirowanen#
All looks good so far.
When I then exit the root user and try to install/remove/search something using my own account, it doesn't work and complains that I am not a sudoer... For example
root@debian:/home/oshirowanen# exit exit oshirowanen@debian:~$ sudo aptitude search ice [sudo] password for oshirowanen: oshirowanen is not in the sudoers file. This incident will be reported. oshirowanen@debian:~$
Why is this happening?
This is what I get from
visudo
# # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d
-
Admin over 11 yearsWhat does your
/etc/sudoers
look like? -
Admin over 11 yearssearch for "oshirowanen" user in /etc/sudoers file: this file has 440 permission with root as owner/group owner: so you must be only able to view the file with superuser priviledges.
-
-
oshirowanen over 11 yearsUpdated question to show what my system has in
visudo
. -
oshirowanen over 11 yearsUpdated question to show what my system has in
visudo
. -
Razzlero over 11 yearsEdited to respond to your edit.
-
oshirowanen over 11 yearsSo everytime I want to use sudo as oshirowanen, I must do
su - oshirowanen
, enter my password, then I can do something likesudo ls
? Looks like I have to dosu - oshirowanen
each and every time? -
Razzlero over 11 yearsNot every time, only after you added your user to the group.
-
oshirowanen over 11 yearsI seem to have to do this every time, i.e. if I want to search, as in
aptitude search ice
, I seem to have to dosu - oshirowanen
[enter password for oshirowanen], then I can dosudo aptitude search ice
[enter password for oshirwanen]. If I just straight tosudo aptitude search ice
, I am told that I am not a sudoer... -
YoloTats.com over 11 years@oshirowanen As l0b0 wrote, you need to completely logout and login again that your current user is in the
sudo
group. After that you should not need thesu - ...
command anymore.