0

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.

1
  • You dont show us the WWW_COMMANDS list, but I notice you use sh in the sudo. Try removing it if it is not in your command list. Commented May 28, 2020 at 12:22

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.