Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I used the Vagrant image for 13.04 from http://cloud-images.ubuntu.com/vagrant/raring/current/raring-server-cloudimg-i386-vagrant-disk1.box to create a new virtual machine and tried to connect to it using ssh. However, the SSH always disconnected immediately, without even getting to the stage where it tried to authenticate.

I opened the VM in the VirtualBox GUI and looked at the SSH log file (auth.log). It was full of lines like this:

Jul 25 17:57:02 vagrant-ubuntu-raring-32 sshd[898]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
Jul 25 17:57:02 vagrant-ubuntu-raring-32 sshd[898]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
Jul 25 17:57:02 vagrant-ubuntu-raring-32 sshd[898]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Jul 25 17:57:02 vagrant-ubuntu-raring-32 sshd[898]: fatal: No supported key exchange algorithms [preauth]

The problem was solved by executing the following commands:

sudo ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa
sudo ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
sudo ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa

I would assume that these should run automatically at some point, especially given that (a) I did not have to run them myself when I installed Ubuntu from an ISO image, and (b) because Vagrant is supposed to be designed that after you run vagrant up you can immediately use the VM without any additional configuration.

I may need to create a large number of Virtual Machines in the near future and I was hoping that I could use Vagrant to do it, but I can't do it if I'm going to have to manually fix SSH on each one.

Does anyone know why this happens and what can be done to fix it? Should I report it as a bug?

share|improve this question
Did you install latest vagrant on you host? How about turning on vagrant debug and see what happnes? vagrant ssh uses vagrant's insecure keypair for pub key authentication. –  Terry Wang Jul 29 '13 at 23:01
Yes, this is the newest vagrant. Note that my problem isn't the vagrant key pair, it's the SSH server's Machine key not being set. If the SSH server has no machine key, there is no way to connect to it. –  Moshe Katz Jul 30 '13 at 16:48
I just tried a fresh 12.10 VM and the same thing happened. –  Moshe Katz Jul 30 '13 at 16:48
Sorry, didn't read the question carefully. I was sshd host key problem not public key authentication. Looks like during the 1st boot Ubuntu cloud image failed to generate the new host keys (if NOT found). It can be done by test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server or use the ssh-keygen to generate the keys. –  Terry Wang Aug 4 '13 at 9:36
There should be test -e /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server in /etc/rc.local script. –  Terry Wang Aug 4 '13 at 9:40
show 1 more comment

3 Answers 3

This is SSH host key problem (NOT related to public key authentication).

Looks like the problem was that the ubuntu cloud vagrant image failed to generate the new host keys (if they are not there in /etc/ssh/) during the 1st boot (vagrant up).

In addition to manually generate the SSH host keys mentioned by Moshe

sudo ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa
sudo ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
sudo ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa

It can also be done by adding the following command in the /etc/rc.local

test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server

Hope it helps.

share|improve this answer
That's a temporary solution, but shouldn't we report it as a bug within that image? Shouldn't all keys be already pregenerated? –  Radek Simko Aug 20 '13 at 7:11
add comment


  • Import ~/.vagrant.d/boxes/raring/box.ovf appliance in VirtualBox

    VBoxManage import ~/.vagrant.d/boxes/raring/box.ovf
  • Get VM Name

    VBoxManage list vms
  • Start the VM

    VBoxManage startvm ubuntu-cloudimg-raring-vagrant-amd64
  • Include the following line in /etc/rc.local (Of course in the VM itself!):

    test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
  • Shutdown VM

    sudo halt
  • Delete old images

    rm ~/.vagrant.d/boxes/raring/box.ovf ~/.vagrant.d/boxes/raring/box-disk1.vmdk
  • Export VM in .ovf format

    VBoxManage export ubuntu-cloudimg-raring-vagrant-amd64 --output ~/.vagrant.d/boxes/raring/box.ovf

Done :)

Did also an bugreport: https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1217950

share|improve this answer
add comment
up vote 3 down vote accepted

This appears to have been a bug in the older base boxes. In the current base box images (generated August 20th, 2013), the keys appear to be created automatically when the box boots up for the first time.

share|improve this answer
I'm running into this bug (again) right now, and it seems by @S0me0ne's bug report that other people are too. I confirmed in /etc/ssh that the key files are not there. This was using the September 24th images. –  malvim Sep 27 '13 at 15:03
Okay, they've just released another "batch" of machines (from Sep 28th, 2013) which create the missing keys correctly. I was able to verify that by importing the boxes using VBoxManage. Weirdly, when I use "vagrant up", the files are not there! Is there a difference between importing directly into VB and using vagrant? –  malvim Sep 28 '13 at 20:07
add comment

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.