I have to execute a shell script as another user, but without being prompted for a password.
I've edited the /etc/sudoers
file with visudo
, adding the following line.
_www localhost=(otheruser) NOPASSWD:bin/sh /path/to/my/script.sh
If I understand how sudo
works, this means that the user _www
is allowed to execute like user otheruser
, without being prompted for password, only from localhost.
Is that correct? Because the system continues to prompt for the password.
visudo
complained when I tested your example. The problem was the relative pathbin/sh
. You should specify the absolute path/bin/sh
as written in the correct reply or no directory pathsh
when the command is in the predefined path. I have this version:visudo -V
---visudo version 1.8.3p1
---visudo grammar version 40