How do I enable a user to run specific sudo commands without the need to type a password?
I already tried the following:
I have a script /usr/local/bin/perform-update
with the rights -rwxr-xr-x 1 root root
:
#!/bin/bash
sudo apt-get update
sudo apt-get -y dist-upgrade
sudo apt-get -y autoremove
sudo snap refresh
I also have a user john
that is part of sudoers. He can execute the command by typing perform-update
, but he will need to type a password. To stop his need for typing his password with this command I tried adding a new line using sudo visudo
:
john ALL=(ALL) NOPASSWD: /usr/local/bin/perform-update
But the user still needs to enter a password when calling the command perform-update
. So I added all the necessary apt and snap commands using sudo visudo
:
john ALL=(ALL) NOPASSWD: /usr/bin/apt update, /usr/bin/apt -y dist-upgrade, /usr/bin/apt -y autoremove, /usr/bin/snap refresh
But the user still needs to enter a password when calling the command perform-update
.
What do I need to do so that he does not have to enter any password when executing perform-update
?
Edit 1:
Based on the answers of @waltinator and @terdon I updated the following.
/usr/local/bin/perform-update
:
#!/bin/bash
sudo apt update
sudo apt -y dist-upgrade
sudo apt -y autoremove
sudo snap refresh
sudo visudo
:
john ALL=(ALL) NOPASSWD: /usr/local/bin/perform-update
john ALL=(ALL) NOPASSWD: /usr/bin/apt update, /usr/bin/apt -y dist-upgrade, /usr/bin/apt -y autoremove, /usr/bin/snap refresh
Unfortunately I am still asked for the password when I call perform-update
as user john
. Where is the error in visudo
?