Post

sudo still asking password although set NOPASSWD in visudo

sudo still asking password although set NOPASSWD in visudo

Challenge

1
2
pi@ubuntu:~$ sudo apt update && sudo apt upgrade -y
[sudo] password for pi:

Solution

Run visudo

1
sudo visudo
1
2
3
4
5
6
7
8
9
10
11
12
13
 43 # User privilege specification
 44 root    ALL=(ALL:ALL) ALL
 45 pi      ALL=(ALL:ALL) NOPASSWD: ALL
 46
 47 # Members of the admin group may gain root privileges
 48 %admin ALL=(ALL) ALL
 49
 50 # Allow members of group sudo to execute any command
 51 %sudo   ALL=(ALL:ALL) ALL
 52
 53 # See sudoers(5) for more information on "@include" directives:
 54
 55 @includedir /etc/sudoers.d

Delete particular user privilege settings in visudo. For this example, on line 45

1
 45 pi      ALL=(ALL:ALL) NOPASSWD: ALL

create a new file in /etc/sudoers.d

1
sudo vim /etc/sudoers.d/users

Insert the user privilege settings inside the file

1
2
# User privilege specification
pi      ALL=(ALL:ALL) NOPASSWD: ALL

Run sudo again to confirm sudo doesn’t ask for password

This post is licensed under CC BY 4.0 by the author.