Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to build an environment that when it finishes bringing the VM up it clones a repository into the share directory. The problem is that the box doesn't have SSH permission on the remote repository.

I have a simple bash script:

cd /vagrant
if [ ! -d "repo" ]; then
  git clone git@remoterepo.com:/my/repo.git

I get the error:

Host key verification failed.

fatal: The remote end hung up unexpectedly

Which makes sense since there is no keys in /home/vagrant/.ssh

I've done a fair bit of googling to no avail, I've tried to set config.ssh.forward_agent = true which allows me to manually clone the repo when I'm ssh'ed into the machine but not when it tries to run itself. I've also tried to specify config.ssh.private_ssh_key = "~/.ssh/id_rsa" but then vagrant simply won't finish loading (I assume the application can't ssh into the box).

So my question is... Do I need to rebuild my base box to include a set of keys and authorize those keys with my remote repo? Or is there an easier solution I'm missing?

note: I've looked at SSH Basics on Vagrant VMs which seem similar but I think this is more about setting up a different user on the box and the solution posted is much more manual than I'd like.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The temporary solution for me was to generate a set of keys and place them in the same directory as the Vagrantfile, then when provisioning I copy the keys over into /root/.ssh/ . There was one small hitch with this and that was that I also had to generate a known_hosts file in order for the VM to accept the connection from the remote server. The known_hosts file also resides in the /vagrant/.ssh/ dir and gets copied over with the keys and everything is now working.

Eventually when I'm not trying to upload a 1GB box to my file host over spotty wi-fi the real solution will be to include these files in the basebox permanently.

share|improve this answer
Did you find a final solution for this (since this one was temporary)? I am looking for something simple like vagrant up and everything works. –  Torsten Nov 28 '13 at 13:17
I rebuilt the basebox with the keys included. –  JaredMcAteer Nov 28 '13 at 15:42
The real question is: Why config.ssh.forward_agent = true in Vagrantfile did not work for this issue? –  noisy May 16 '14 at 22:26
I'm not sure. I use config ssh.forward_agent = true now and it works. Maybe the version of Vagrant I was using in 2013 was bugged. –  JaredMcAteer Feb 19 at 16:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.