I'd like to move a an ssh key into vagrant and put them in ~/.ssh
, what's the easiest way of doing that? I have the following in my Vagrant file:
config.vm.synced_folder "conf.d", "/svr/conf.d"
config.vm.provision :shell,
:inline => "ls -l /svr/conf.d/.ssh"
total 4 -rw-r--r-- 1 vagrant vagrant 1670 Mar 26 08:19 id_rsa.mediapop
config.vm.provision :shell,
:inline => "cp /svr/conf.d/.ssh/id_rsa.mediapop /home/ubuntu/.ssh/id_rsa"
config.vm.provision :shell,
:inline => "ls -l /home/ubuntu/.ssh"
total 4 -rw------- 1 ubuntu ubuntu 0 Mar 22 08:56 authorized_keys -rw-r--r-- 1 root root 1670 Mar 26 08:59 id_rsa
but then when I do vagrant ssh -c "ls -l ~/.ssh"
I get:
$ vagrant ssh -c "ls -l ~/.ssh"
total 4
-rw-r--r-- 1 vagrant vagrant 409 Mar 20 04:47 authorized_keys
So vagrant is overwriting my .ssh
directory.
I put my SSH file in
conf.d/.ssh/id_rsa.medipop
and then did:Which worked splendidly once I realised the vagrant user is
vagrant
notubuntu
(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 yourVagrantfile
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:
I'm really surprised that Vagrant doesn't provide this by default!
Take a look at the Vagrant Shell Provisioner, you'd add this to your Vagrantfile.
However, depending on what you're trying to achieve, it's probably better to use the supplied ssh key to access Vagrant.
To generate a quick config file to be added to your
~/.ssh/config
, including an identity file line run$ vagrant ssh-config
. You could then$ ssh you-vagrant-box
rather than$ vagrant ssh
.To move both private and public keys the following will work: