Hi i'm having a real problem trying to run a script as root, the script is to use sudo to run wp-cli as the user required.

The command I am using is

sudo -u hstestsite1 -s "cd /home/hstestsite1/public_html; /usr/local/bin/wp plugin list"

I receive

/bin/bash: cd /home/hstestsite1/public_html; /usr/local/bin/wp plugin list: Permission denied

However if I su to that user and run the command it all works fine

su - hstestsite1
cd /home/hstestsite1/public_html; /usr/local/bin/wp plugin list
| name    | status   | update | version |
| akismet | inactive | none   | 3.3.3   |
| hello   | inactive | none   | 1.6     |

Any ideas?


  • is your script trying to exeute the entire command "cd /home/hstestsite1/public_html; /usr/local/bin/wp plugin list" ? – LotoLo Jul 17 '17 at 15:20

Sudo doesn't handle multi-line commands in its shells, but you can create a shell inside of your sudo command and have that shell run multiple commands, like so:

sudo -u hstestsite1 -s sh -c "cd /home/hstestsite1/public_html; /usr/local/bin/wp plugin list"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.