I'm trying to write a simple drush alias to connect to a Drupal site running on a local Vagrant instance.

I have the following in a file called ~/.drush/l.aliases.drushrc.php:

$aliases['o'] = array(
  'parent' => 'l',
  'root' => '/vagrant/docroot',
  'remote-host' => '',
  'remote-user' => 'vagrant',
  'ssh-options' => '-p 2222 -i ~/.vagrant.d/insecure_private_key',
  'uri' => '',

The alias is found. drush sa returns:


However, when I drush @l.o status it doesn't connect to the remote host:

PHP executable        :  /usr/local/bin/php
PHP configuration     :  /usr/local/etc/php/5.3/php.ini
PHP OS                :  Darwin
Drush version         :  6.1.0
Drush configuration   :

I have confirmed that this command successfully connects to vagrant:

ssh [email protected] -p 2222 -i ~/.vagrant.d/insecure_private_key

Debugging output doesn't show an SSH command so far as I can tell:

SIG-106:ilob justin$ drush --debug @l.o status
Bootstrap to phase 0. [0 sec, 3.78 MB]                               [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.01 sec, 3.98 MB] [bootstrap]
Loaded alias @l.o from file /Users/justin/.drush/l.aliases.drushrc.php [0.01 sec, 3.99 MB]                                                                        [notice]
Cache MISS cid: 6.1.0-commandfiles-0-807b6772846e18b2741e8d5b7119b4cc [0.01 sec, 4 MB]                                                                             [debug]
Cache SET cid: 6.1.0-commandfiles-0-807b6772846e18b2741e8d5b7119b4cc [0.01 sec, 4.02 MB]                                                                           [debug]
Bootstrap to phase 0. [0.05 sec, 9.56 MB]                                                                                                                      [bootstrap]
Found command: core-status (commandfile=core) [0.08 sec, 9.56 MB]                                                                                              [bootstrap]
Loading outputformat engine. [0.13 sec, 9.6 MB]                                                                                                                   [notice]
Calling hook drush_core_status [0.14 sec, 9.65 MB]                                                                                                                 [debug]
Returned from hook drush_core_status [0.14 sec, 9.66 MB]

I know I must be doing something stupid but I just can't see it.

  • What does drush --debug @l.o status show? The exact ssh command should be buried in the output.
    – mpdonadio
    Mar 20, 2014 at 19:57
  • FWIW, I always use .ssh/config for setting up SSH connection info instead of the drush options.
    – mpdonadio
    Mar 20, 2014 at 19:58
  • Hmm, there is no ssh command of any kind in the debug output. Debug added above.
    – Justin
    Mar 21, 2014 at 14:15
  • Do other non-Vagrant, but remote, aliases work? The debug you posted shows that it didn't even attempt the remote connection (you should see lines beginning 'Begin redispatch via invoke process' and 'Backend invoke: ssh ...'
    – mpdonadio
    Mar 21, 2014 at 15:46
  • Yes, I have many and they all do.
    – Justin
    Mar 21, 2014 at 19:38

3 Answers 3


I was able to use drush alias with following configuration:

Let's assume two things:

  • vagrant box has some sort of static ip (can be private, for example:

  • IP of vagrant is available in symbolic form (for example, we have single line in /etc/hosts with ip and hostname). (for example: test.site.local).

Step 1: We need to copy settings, generated by vagrant ssh-config command into $HOME/.ssh/config

Host test.site.local
    IdentitiesOnly yes
    UserKnownHostsFile /dev/null
    StrictHostKeyChecking no
    PasswordAuthentication no
    IdentityFile [path to vagrant private insecure key]

Step 2: With such configuration, my alias was in following form:

$aliases['example'] = array(
   'root' => '/var/www',
   'uri' => 'test.site.local',
   'remote-host' => 'test.site.local',
   'remote-user' => 'vagrant',
   'ssh-options' => "-i path_to_insecure_private_key"
  • This is a really nice solution. I didn't specify any ssh-options in my alias file having used "vagrant ssh-config", everything I needed was there.
    – Angry Dan
    Feb 9, 2015 at 16:22
  • This worked nicely, though in my case I had to set root like so: 'root' => '/vagrant/docroot' Jun 17, 2015 at 17:28
  • Using /dev/null as the known hosts file results in a warning every time drush is run. I point it to HOME/.ssh/known_hosts_vagrant to use a separate file. Then the warning is only shown once.
    – Tim
    Aug 8, 2017 at 5:58

The character ~ is expanded by Bash. Drush does not provide this same service, so you should replace ~ with the path to your home directory.

So, for example:

$home = drush_server_home();
$aliases['o'] = array(
  'parent' => 'l',
  'root' => '/vagrant/docroot',
  'remote-host' => '',
  'remote-user' => 'vagrant',
  'ssh-options' => "-p 2222 -i $home/.vagrant.d/insecure_private_key",
  'uri' => '',

That's untested, but it should work, baring any simple typo's.


I think I see a Drush bug here. Drush is going to assume that is going back to the local machine, and will decide not to use ssh w/out even considering the implications of the -p in ssh-options. This is going to require a patch to Drush to fix. function drush_is_local_host() in environment.inc.


Please put any comments regarding potential fixes in the Github issue, Drush backend invoke does not consider port number when deciding local vs remote.


I got around this by simply doing a check for Drush in my local settings.php file via php_sapi_name() == 'cli' and updating my database and memcache connection strings to Vagrant, like this:

if (php_sapi_name() == 'cli') {
  $databases['default']['default']['port'] = '3307';

  $conf['memcache_servers'] = array(
    '' => 'default',

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.