run a script as another user without password
You can run a program/script/command as another user the following way (example):
sudo -u www-data /bin/date
/bin/date is executed in the name of
www-data and you get the output. However, it asks for your password.
Question: how to execute the command above without a password check?
Create the file
jabba ALL=(www-data) NOPASSWD: /bin/date
Meaning: allow the user “jabba” to execute “/bin/date” in the name of “www-data” and ask no password.
You should read
/etc/sudoers.d/README, it contains important pieces of information:
- the file you create cannot contain ‘
~‘ or ‘
- the file must have 0440 rights
- the command at the end of the lines must have absolute path
Tip from here.