How can I move my deploy key into vagrant?

I put my SSH file in conf.d/.ssh/id_rsa.medipop and then did:

config.vm.synced_folder "conf.d", "/svr/conf.d"
config.vm.provision :shell, 
:inline => "cp /svr/conf.d/.ssh/id_rsa.mediapop /home/vagrant/.ssh/id_rsa"

Which worked splendidly once I realised the vagrant user is vagrant not ubuntu (which is why I was confused in my question as to why my ssh key seemed to disappear).


What about SSH Agent Forwarding?

Make sure your SSH key works locally first then add config.ssh.forward_agent = true to your Vagrantfile to pass through.

Vagrant details here: http://docs.vagrantup.com/v2/vagrantfile/ssh_settings.html


You can use Ruby's core File module, like so:

  config.vm.provision "shell" do |s|
    ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
    s.inline = <<-SHELL
      echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
      echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
    SHELL
  end

I'm really surprised that Vagrant doesn't provide this by default!

Tags:

Vagrant