How to run a shell command as another user without Shell Access enabling

It needs if you don't want to waste time to enable Shell Access for specific user to run some command from his shell

sudo -H -u someuser bash -c 'uptime'

Example of using:

cd ~someuser/www
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mv wp-cli.phar wp
sudo -H -u someuser bash -c './wp plugin status'

or

sudo -H -u `pwd |cut -d/ -f3` bash -c './wp plugin status'

It will show a status of installed WP plugins for this user using wp-cli tool

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *