简体   繁体   中英

PHP Sudo permissions only works for 'ALL' commands when using exec()

I need my PHP code to run scripts as a different user with exec(), and so in the sudoers file I added: www-data ALL=(csgo) NOPASSWD: WWW_COMMANDS where WWW_COMMANDS is an alias list of the scripts i need to run. While this works fine when I use su -s /bin/bash www-data to log in as php and test if it works through ssh, when I try to actually send the command on my site with exec("sudo -u csgo sh /path/to/script.sh") and print the output it tells me sudo: no tty present and no askpass program specified and the script will not have run. I also added Defaults:www-data !requiretty to my sudoers file to no effect. The only way I can get it to work when running the exec() on my page is to set www-data ALL=(csgo) NOPASSWD: ALL , which obviously isn't a great solution. Anyone know why this is happening / how to fix it.

I didn't even know a script would run without a. or a sh. meuh's comment worked, removing the sh before the command fixed the issue.

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