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?

  • 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 Oct 8 '13 at 12:20
  • Drush can do this without 'su', so on-topic. – greg_1_anderson Oct 8 '13 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 Oct 8 '13 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. – JamesWilson Dec 10 '13 at 13:02
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 www-data@server.example.com, and you'll be all ready to go.

|improve this answer|||||
  • Is there anything Drush can't do? :P – Clive Oct 8 '13 at 14:15
  • 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 Oct 9 '13 at 7:47
  • @klausi then my first comment under your question apply, I'm afraid. – Mołot Oct 9 '13 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 – greg_1_anderson Oct 9 '13 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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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