Vagrant ssh fails with VirtualBox

I have had the same problem with the box given in the "Getting started" of Vagrant site. My solution below is for this tutorial's box.

I find a solution here : https://github.com/mitchellh/vagrant/issues/391

  1. in the VagrantFile, add the gui mode : config.vm.boot_mode = :gui
  2. run vagrant up
  3. in the gui, log with the user "vagrant" (password = "vagrant")
  4. int the gui, run sudo /etc/init.d/networking restart, in /etc/network/interfaces file, you must now have a section with #VAGRANT-BEGIN [...]#VAGRANT-END
  5. run vagrant reload on the physical machine

I saw this problem with my setup and eventually narrowed it down to the fact that I'd added a name onto the local hosts file. So I had:

127.0.0.1 localhost myname myalias

Removed the myalias which I'd added and it booted okay. Thanks to @saphirlazuli for the clue that it was networking related.


This is an intermittent problem for me, and definitely seems to be related to networking. I found some more helpful information at Vagrant GitHub issues #391 and #455. I tried deleting my unused host-only network in VirtualBox settings (as recommended as a potential fix in one of the GitHub issues) which didn't seem to help.

Starting in gui mode (as described in a previous answer) is a great way to debug/fix problems. I found that it's because for whatever reason, the VM cannot obtain an IP address on startup. Starting in GUI mode then logging in (vagrant/vagrant) and running sudo dhclient in the guest OS would retrieve the IP address and the Vagrant setup process would complete successfully.

Still looking for a permanent fix though.

Hope this helps!

[EDITED TO ADD]: A helpful suggestion was added to GitHub Issue #455 which involves adding the following config to your Vagrantfile:

config.ssh.max_tries = 150

This is currently working for me, and seems to make sense since the problem seems to be related to timeout - increasing the number of tries should increase the probability of the SSH process succeeding in time. It's an intermittent issue in the first place so I'll reserve judgement for a while, but fingers crossed it'll work! Thanks to karel1980 for suggesting the fix.