3

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:

<?php

$aliases['accounting-phd'] = array(
  'root' => '/var/www/example/docroot',
  'uri' => 'example.com',
  'remote-host' => 'server.example.com',
  'ssh-options' => '-t',
  'path-aliases' => array(
    '%drush-script' => '/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?

4
  • This question appears to be off-topic because it is about Linux console configuration and scripting, not about Drupal itself, and should be asked on Server Fault or vendor specific site like Ask Ubuntu (if you're on Ubuntu server).
    – Mołot
    Commented Oct 8, 2013 at 12:20
  • Drush can do this without 'su', so on-topic. Commented Oct 8, 2013 at 14:11
  • @greg_1_anderson oh, the sudo in title caught me. Vote retracted. But configuring sudo would be off-topic here, I'm sure it would ;)
    – Mołot
    Commented Oct 8, 2013 at 14:25
  • I'm curious if you ever figured this out Klausi, or asked anywhere else? I've hit the same exact problem here. Commented Dec 10, 2013 at 13:02

2 Answers 2

4

Set 'remote-user' => 'www-data' in your site alias, and Drush will exec the remote Drush as the www-data user. ssh-copy-id [email protected], and you'll be all ready to go.

3
  • That only works if the www-data user is allowed to SSH into the machine, which is currently not the case. That's why I explored sudo in the first place.
    – klausi
    Commented Oct 9, 2013 at 7:47
  • @klausi then my first comment under your question apply, I'm afraid.
    – Mołot
    Commented Oct 9, 2013 at 11:12
  • Yep, I agree, it's off topic. You might try sudo -u www-data drush $@, with an appropriate entry in sudoers, but I'm not going to spend the time to get the quoting right. Ask in another forum, like serverfault.com Commented Oct 9, 2013 at 20:29
0

I'm having a similar issue I'm working with, and got a basic shell wrapper working with this code:

#!/bin/bash
sudo -u www-data -c 'drush6 $@'

I think the double quotes may have been your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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