Unix & Linux
debian sudo users root su
Updated Fri, 20 May 2022 07:32:14 GMT

adding a sudoer in debian


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.




Solution

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




Comments (5)

  • +0 – where should I place the youruser ALL line? the %sudo ALL=(ALL:ALL) ALL is already there — Jun 28, 2016 at 10:26  
  • +0 – after the line: "%sudo ALL=(ALL:ALL) ALL" You should replace "youruser" with your username in the example. — Jun 28, 2016 at 10:27  
  • +0 – but I do want the user to be prompted for a password — Jun 28, 2016 at 10:30  
  • +0 – use the following code: youruser ALL=(ALL) ALL — Jun 28, 2016 at 10:33  
  • +0 – If there is an (syntax) error in Your /etc/sudoers you may loose your sudo access at all.- Use visudo instead. — Jul 19, 2021 at 08:21