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?
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
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.
Workaroud:
Import ~/.vagrant.d/boxes/raring/box.ovf appliance in VirtualBox
Get VM Name
Start the VM
Include the following line in /etc/rc.local (Of course in the VM itself!):
Shutdown VM
Delete old images
Export VM in .ovf format
Done :)
Did also an bugreport: https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1217950
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.