简体   繁体   中英

Executing a bash script from a web page via PHP's shell_exec(), which requires another user's perms?

I have a couple of bash scripts on a Centos box which I use to do basic server admin stuff like restart services, etc. I run these as a standard user who is also the scripts' owner.

I tried to run these using shell_exec() in PHP, with the apache user, but it simply doesn't work - I'm guessing it doesn't have enough permissions (even with 775 and being in the correct group!) to run everything I want it to.

I've tried editing the sudoers file giving apache permission to run the script calls but it still doesn't work and has no error messages that I can see.

Any thoughts? How can one trigger a script from a web page which requires a different user to run?

Make sure safe mode is off. Also verify the user is the one you expect:

<?php echo exec('whoami'); ?>
  1. check under which user is running apache ( for debian it is www-data)
  2. add www-data in sudoers list with permission to execute files that you like
  3. check which shell has www-data user in /etc/passwd (you will need to give valid shell)
  4. run script with /bin/bash -x (it will output for sure)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM