views:

51

answers:

1

I'm trying to run a shell script owned by a non-privileged user from PHP on an Ubuntu server. Issues with permissions make running it with exec() impractical, as it's www-data that's running it. I've googled a bit and found varius references to suExec (which seems too much of a hassle to get working for such a small problem), setting the suid bit, and an interesting approach here on Stackoverflow involving a Python server listening for commands sent by PHP.

Anyway, of all of these solutions, I lean towards the one involving setting the suid bit, tried it and it didn't work : chmod u+s script.sh, and my Apache logs still show permission errors, so I know the script is not running as it's owner but as www-data.

What do I have to do to get this working, and is there a simpler solution for this problem ?

A: 

Take a look at the man page for sudo: sudo -u your_other_user will let you execute the command as the other user.

Also use man sudoers to look for options on which user can execute what commands with sudo.

Residuum
Looking into your solution but so far no luck in getting it to work. I've tried enabling password-less sudo for the specific command that's supposed to run in the sudoers file : `www-data ALL=(ALL) NOPASSWD: /user/bin/sudo -u user /path/to/command` But if I `su www-data` and try to run it still asks for a password. Same with `/user/bin/sudo -u user`
Andrei