Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to run a script which executes a chain of commands under another user on a remote server. The script contains the following ssh command to return information about the remote user's Drupal installation. My sudoers user's public key is in place and working properly.

The following example does not work and just stops without any output:

$ssh sudoers_user@remote.server "sudo -u another_user -s;cd ~/htdocs;drush status;"

When I enter the chained commands manually in the console it works fine.

I do also get good results with:

$ssh sudoers_user@remote.server "ls -al /var/www/vhosts/"

Please advise where I go wrong. Thank you.

share|improve this question
im curious why you want to login as sudoers_user and then sudo -s to another user? If you coulr ssh as another_user directly, that'd save you some trouble. I'd check the /etc/sudoers file, and also the logs; if you've got a failed sudo attempt it would probably be logged... – Petter H Jun 13 '13 at 11:15
Being a Support staff member (suoers_user) I want to login to a client's vhost (another_user) environment and do stuff. This works correctly when I type the individual commands. When I run my script to gather info from a remote user's vhost the commands I normally type are concatenated into one line, and fails. I will check the logs. – Tom Jun 13 '13 at 11:35

By default, sudo is expecting interactive password authentication. You need to either ssh in as the sudoers_user or you need to use the NOPASSWD: modifier in sudoers for that source/target user pair.

share|improve this answer
The NOPASSWD is already specified in the sudoers file for the usergroup of my sudoer_user. I do login using sudoers_user and then try to sudo to the clients system user to do stuff. – Tom Jun 13 '13 at 11:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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