How to load a local ssh key for remote connection from bedrock-ansible VM

Hello,

I’d like to ask what is the simplest way to configure bedrock-ansible so that my local private key is automatically loaded into the VM and added as identity.

I want to be able to use the ssh key that I’m using on the host machine to be able to ssh to Github and other servers (e.i. staging, production) from the VM provisioned with bedrock-ansible. These remote servers alread have ny public key added.

I will only add that I’ve configured agent forwarding in ~/.ssh/config where I provided my VM’s IP address and set ‘ForwardAgent’ to ‘yes’. I can also see that config.ssh.forward_agent is set to true in the Bedrock-Ansible Vagrantgile.

Nevertheless, the identity is not added inside the VM.

Thanks.

@luqo33 With SSH forwarding, you shouldn’t need to load your private key in the vm.

To test whether your SSH forwarding is set up, don’t check for the private key on the vagrant vm, just see if you can SSH into the vm and connect from there to Github, etc.

If you haven’t already, look through these tips for SSH forwarding:

All the above applies to connections like this:

local machine  =ssh=>  vagrant vm     =ssh=>  git repo
local machine  =ssh=>  remote server  =ssh=>  git repo

If you’re trying to do either of these

local machine  =ssh=>  vagrant vm  =ssh=>  remote server
local machine  =ssh=>  vagrant vm  =ssh=>  remote server  =ssh=>  git repo

then I’m a little baffled why. Why not just cut out the vagrant vm middleman (i.e., connect straight local machine =ssh=> remote server)? That way you wouldn’t need to move private keys around or deal with complex forwarding chains.

1 Like

Hi @fullyint. I appreciate your reply. I followed the directions as per https://developer.github.com/guides/using-ssh-agent-forwarding/, and got the forwarding agent working.

To answer your question why I’d like to ssh to the VM and later to the remote server - I’m using capistrano-wpcli to synchronize databases between environments. I need to execute cap commands relating to the database from inside the VM because this is where the mysql server is running. This makes it necessary to ssh into the VM and then pull/push to staging/production.

Once again thank you.

1 Like