ideasonpurpose / basic-wordpress-vagrant

A fast, easy to use WordPress Vagrant environment modeled after managed WordPress hosting platforms like WP Engine and Flywheel.
MIT License
25 stars 3 forks source link

WP-CLI @alias without password #29

Closed jgraup closed 8 years ago

jgraup commented 8 years ago

Currently I have a basic.dev box setup and an @basic alias in my ~/.wp-cli/config.yml to point to http://basic.dev/.

@basic:
    ssh: vagrant@172.28.128.7/var/www/wordpress/ 

Outside of Vagrant I can run wp @basic theme list but I'm prompted for a password.

Do you have a work-around for password prompting when using an @alias outside of the vagrant box?

joemaller commented 8 years ago

I just read over the wp-cli config docs and it doesn't look like the ssh: option can take additional SSH args. The way Vagrant connects internally is to reference a generated VM-specific SSH key. The vagrant ssh command includes something like this:

-o StrictHostKeyChecking=no -o 'IdentityFile="/Users/joe/basic-wordpress-vagrant/.vagrant/machines/default/virtualbox/private_key"'

What you could do is edit your ~/.ssh/config file to include the key and user. A clause like the following should allow you to connect to the VM without a password:

Host basic-wordpress-vagrant.dev
User vagrant
IdentityFile ~/basic-wordpress-vagrant/.vagrant/machines/default/virtualbox/private_key

The private key is created by vagrant up in the hidden dot-folder for every VM. If you reuse the same paths, this should work fine across up/destroy/up cycles too.

Once SSH is configured, your .wp-cli/config.yml command might just be this:

@basic:
    ssh: basic.dev/var/www/wordpress
jgraup commented 8 years ago

This seems to be working well for me. Thanks for the help!


~/.wp-cli/config.yml

@basic:
    ssh: basic.dev/var/www/wordpress/

~/.ssh/config

Host basic.dev
    HostName basic.dev
    User vagrant
    IdentityFile ~/sites/basic.dev/.vagrant/machines/default/virtualbox/private_key

wp @basic theme list