0

I have added my user in sudoers file, after a restart ubuntu still requires password to execute command.

Below is my sudoers file.

root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin 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

aman    ALL=(ALL:ALL) ALL

Here "aman" is current loggedin user name.

Actually in my ubuntu 16.04 I am facing wifi issue which I am able to resolve using below command but I want to execute this command on startup without prompting for password.

systemctl restart network-manager.serviceroot

I have also tried below command but no sucess, every time I am going to execute command ubuntu prompt me to enter password.

usermod -aG sudo username

UPDATE :- Now below is my sudoers file screen shot

enter image description here

Note:- When I execute whoami command terminal shows "aman"

Below is the image shows me as i am administrator enter image description here

1
  • The command is ystemctl restart network-manager.service without "root" at the end. What you want to do is a tremendous bad use of privilege separation which is here to protect your system.
    – kcdtv
    Feb 22, 2018 at 15:59

3 Answers 3

4

You should use NOPASSWD option

aman ALL=(ALL) NOPASSWD:ALL

However, I would not recommend it that way, because user aman can execute anything without password. I would only allow the systemctl command to be executed without password like this:

aman     ALL=NOPASSWD:/bin/systemctl

It is safer that way.

2
  • thanks for reply but this also not works, ubuntu still aks me for password. Feb 22, 2018 at 16:12
  • this is much safer than @Félicien's suggestion to add NOPASSWD:ALL (no password required to run any program)
    – phette23
    May 21, 2021 at 16:03
3

This is the normal behaviour, being in the sudoers list only means that you can use the sudo command, but you'll be asked for your password.

If you want to use sudo without password, you need to add NOPASSWD:ALL after aman ALL=(ALL:ALL) in /etc/sudoers

(the line would look like aman ALL=(ALL:ALL) NOPASSWD:ALL)

see here

2
  • thanks for reply but this also not works, ubuntu still aks me for password. Feb 22, 2018 at 16:13
  • weird ... I just tried and it worked for me
    – Félicien
    Feb 22, 2018 at 16:38
0

I dont know if its too late to answer. But I ran into same problem recently and nothing was working. So in case you login to server using ssh keys without password, you can try below steps:

  1. Add user to sudoers file.
sudo visudo
username ALL=(ALL) NOPASSWD:ALL
  1. Then delete the password for user.
sudo passwd -d `whoami`

Now you will be able to run any sudo commands without password.

2
  • 1
    Deleting the user's password is a bad idea.
    – raj
    Oct 13, 2021 at 9:31
  • This is only in case the login is based on keys mechanism and not using any passwords for login. Oct 14, 2021 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.