Drush remote with switching shell users (sudo) Problem: I have a remote server with SSH access where the Drupal site can only be accessed as another user (www-data). My own shell user is not able to use drush directly for security reasons.

So how can I run all drush remote commands as www-data? I have sudo priviledged to execute commands as root.

My aliases.drushrc.php:

&lt;?php

$aliases['accounting-phd'] = array(
  'root' =&gt; '/var/www/example/docroot',
  'uri' =&gt; 'example.com',
  'remote-host' =&gt; 'server.example.com',
  'ssh-options' =&gt; '-t',
  'path-aliases' =&gt; array(
    '%drush-script' =&gt; '/home/klausi/drush-remote.sh',
  ),
);


And in drush-remote.sh on the server:

#!/bin/bash
sudo su www-data -c "drush $@"


This prompts me for my password successfully, but then fails with

su: unrecognized option '--root=/var/www/example/docroot'
Usage: su [options] [LOGIN]


How can I separate the options from the su command?
Set 'remote-user' => 'www-data' in your site alias, and Drush will exec the remote Drush as the www-data user.  ssh-copy-id www-data@server.example.com, and you'll be all ready to go.