0

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 [email protected] "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 [email protected] "ls -al /var/www/vhosts/"

Please advise where I go wrong. Thank you.

2
  • 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, 2013 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, 2013 at 11:35

1 Answer 1

1

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.

1
  • 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, 2013 at 11:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .