Bash – Linux bash: run script as a non-root user by a non-root user using PHP

bashpermissionsphp-fpm

I have a PHP script owned by "tom" (runs using PHP-FPM). "tom" wants to run the script /srv/helloworld.sh as another user called "jerry". "tom" has the access to run scripts on the server (so he can use ex. system()).

The long and the short, "tom" wants to know how to do this.
"tom" readed some article about this:

sudo su -c /srv/helloworld.sh jerry

But the main problem is that, the script asks for a password and you know, (if I am not mistaken) there is no way to enter password in a web interface.

I am really curious about this topic and I would be pleased if you could help me. Thanks in advance!

Best Answer

man sudoers has all the information you need.

You need the command sudo -u jerry /srv/helloworld.sh and have to change /etc/sudoers so that tom is allowed to execute this without having to enter a passwort. NOPASSWD is your key word.