adding a sudoer in debian
Solution 1
As root edit /etc/sudoers and place the following line:
youruser ALL=(ALL) NOPASSWD:ALL
after
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
In this way you will be capable to execute all commands that require sudo privileges passwordless.
In order to use sudo and be prompted for a password you need to remove
NOPASSWD:ALL
Solution 2
Following command is correct and enough but you need to completely logout the user and relogin to work .
usermod -a -G sudo user
Solution 3
In addition, in Debian if it doesn't work you need to install sudo package:
apt install sudo
Then you should have /etc/sudoers
file and proceed as follows:
usermod -a -G sudo user
Solution 4
You need to run the following command as root: (where USERNAME
is replaced with your actual username)
usermod -aG sudo USERNAME
It won't work if you try to run this command under an unprivileged user.
So to gain root rights and to make sure that the necessary packages are installed, do this:
su
[enter password for your root user]
apt update
apt upgrade
apt install sudo
apt install usermod
usermod -ag sudo USERNAME
reboot
Don't forget to reboot at the end!
After the reboot the user should be able to use sudo
commands.
Tip: if you tried to run a long command which failed because it actually requires sudoer rights, you can use the following trick to run the command again but this time with the correct privilege:
sudo !!
Related videos on Youtube
ValarMorghulis
I am a C developer interested in malware analysis and design. Self study C, Win32, x86 and python. Studying Windows rootkits, Linux rootkits and SCADA systems malware.
Updated on September 18, 2022Comments
-
ValarMorghulis over 1 year
After a long search on the web, trying everything I can find I came to ask you guys, how can I add an existing user to be a sudoer?
I've tried
usermod -a -G sudo user
and also
adduser user
both while in root... the first one didn't work at all and the second one supposedly added 'user' to sudoers but when I try to run sudo with that user it says: user is not in the sudoers file. This incident will be reported.
When I run adduser again, it says the user 'user' is already a member of 'sudo'.
what can I do???
-EDIT: for clarification, I do want the user to be prompted for a password when trying to run sudo. currently when the user is running sudo he is being prompted for a password and then he gets "user is not in sudoers file...." I wand him to be able to run sudo, be prompted and then escalate the privilege.
-
ValarMorghulis almost 8 yearswhere should I place the youruser ALL line? the %sudo ALL=(ALL:ALL) ALL is already there
-
Ivan P almost 8 yearsafter the line: "%sudo ALL=(ALL:ALL) ALL" You should replace "youruser" with your username in the example.
-
ValarMorghulis almost 8 yearsbut I do want the user to be prompted for a password
-
Ivan P almost 8 yearsuse the following code: youruser ALL=(ALL) ALL
-
Michael Platings over 6 yearsI've found that logging out and logging in again often isn't enough, but a full restart is required.
-
vhs over 4 yearsIf you've already manually created
/etc/sudoers
, an interactive prompt will ask you if you'd like to replace it with the default installed from Apt. -
sneaky almost 3 yearsIf there is an (syntax) error in Your
/etc/sudoers
you may loose your sudo access at all.- Usevisudo
instead.