Vagrant: Failing to connect to box via ssh - connection closed by remote host

Created on 9 Jul 2011  ยท  31Comments  ยท  Source: hashicorp/vagrant

I'm trying to test out vagrant but am having an issue with creating a basic box. Commands I am running are:

>: cd Desktop/
>: mkdir vagrant-test
>: cd vagrant-test/
>: vagrant init lucid32
      create  Vagrantfile
>: vagrant up
[default] Importing base box 'lucid32'...
[default] Matching MAC address for NAT networking...
[default] Running any VM customizations...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- ssh: 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] Failed to connect to VM!
Failed to connect to VM via SSH. Please verify the VM successfully booted
by looking at the VirtualBox GUI.
>: vagrant ssh
ssh_exchange_identification: Connection closed by remote host

Vagrant version 0.7.6 and Virtualbox 4.0.10 on Mac OS X 10.6.8

Most helpful comment

My virtualbox is 5.1.2 and vagrant is 1.8.5 in redhat 6.5:

I just: vagrant reload ==> vagrant up ==> vagrant ssh
This worked for me.

I hope this can help.

All 31 comments

Following on directly from the above commands, if I do the following, it appears to work:

>: vagrant destroy
[default] Forcing shutdown of VM...
[default] Destroying VM and associated drives...
>: vagrant up
[default] Importing base box 'lucid32'...
[default] Matching MAC address for NAT networking...
[default] Running any VM customizations...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- ssh: 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- v-root: /vagrant
>: vagrant ssh
Linux lucid32 2.6.32-28-generic #55-Ubuntu SMP Mon Jan 10 21:21:01 UTC 2011 i686 GNU/Linux
Ubuntu 10.04.2 LTS

Welcome to Ubuntu!
 * Documentation:  https://help.ubuntu.com/
Last login: Sun Jul  3 18:08:10 2011
vagrant@lucid32:~$ logout
Connection to 127.0.0.1 closed.

I am also having this issue with the same setup, tested with lucid32 and lucid64. No amount of destroying and uping will fix the issue, I have to start the box in gui mode and run sudo /etc/init.d/networking restart to connect via ssh.

@roryf what versions of VirtualBox and Vagrant are you using? and which OS and version?

@davidwinter as I said, the same setup - Vagrant version 0.7.6 and Virtualbox 4.0.10 on Mac OS X 10.6.8

I have now tried uninstalling VirtualBox and Vagrant, downloading VB 4.0.12 and installing that from scratch, and reinstalling Vagrant. However, no change.

I'm getting the same behaviour.

Mac OS 10.6.8
Vagrant version 0.7.7
VirtualBox 4.0.12
Box: lucid32 (downloaded 17th July 2011)

Have to startup with GUI and restart networking before I can SSH in and run provisioning.

I also tried re-downloading the lucid32 box, but no difference.

Hi all, just another "me to" on Mac OS 10.6.8, Vagrant version 0.7.7, and VirtualBox 4.0.10.

Exact same problem. On lucid32, lucid64 and I built a custom debian box and the same problem.

Logging in and restarting networking gets things going.

This is really weird. So now, vagrant up is working fine. No changes to the software, or a reboot of the host machine. It did this a few days ago, started working again then stopped again on Thursday or Friday last week.

Is there anyway of getting vagrant output what it is doing when it's hanging waiting for the vm to boot so we can help debug?

Hmm something worth trying is this suggested on stackoverflow:

http://stackoverflow.com/questions/4681070/vagrant-ssh-fails-with-virtualbox/6677832#6677832

As I am currently unable to get it to break this morning I'm not sure if it helps.

Oh as I typed this I'm wondering if it has anything to do with multiple active network devices on the host? I have wifi enabled on one network and a LAN on another network..

I only have one physical network device on the host, but also have VMware Fusion network interfaces.

Having hard rebooted the host a few days ago, when I next up'd the same VM I didn't have this issue, but it wasn't a re-provision from scratch and I'm not sure what state the reboot left the VM in, presumably some sort of suspend mode.

Will test again with updated vagrant and VirtualBox and download the latest lucid32.

Ah I've come home and I am now able to get it to timeout. The only difference at home is that I am on wifi with no wired network connection.

I'm not in the office for 2 days now, I might be able to find an Ethernet connection to see if its a wifi vs lan issue at some point.

Experiencing same on same environment as @roryf

Confirming this is still an issue on OS X 10.7, vagrant 0.8.2 and VirtualBox 4.1.0, with lucid-32 box downloaded today.

Can those experiencing this issue take a look at issue #391, particularly the output from netstat -an, or lsof -i :222 in the the working/not-working cases. Please add your failing and passing configuration details to this page:
https://github.com/jedi4ever/veewee/wiki/vagrant-(veewee)-+-virtualbox-versions-test-matrix

@davidwinter, if this issue is as described in issue #391 could you close this issue?

I've got the same problem with VirtualBox 4.1.0 and Vagrant 0.8.6 on OS X 10.6.8.

It's quite weird, cause first time it worked out of the box, but when I added provisions support, and reload, it stopped connecting. Even when I removed provisions it doesn't connect.

@sparrovv, I haven't tested this, but I think that in certain circumstances, installing apache "again" can overwrite your ssh keys/users (maybe?) and disallows access. In my situation, I would vagrant up, run postinstall.sh and then, via tasksel, install LAMP. Everything worked fine will still connected but if I tried vagrant halt, or anything else except suspend or halt --force, I got a network error. Then if I finally got it shut down, I couldn't connect back to it. Like I said, I think this may be due to installing LAMP (specifically Apache) in my case, so if you're provisioning Apache, that could be the issue.

@ehaughee I used this workaround: https://github.com/mitchellh/vagrant/issues/391#issuecomment-2078383

Any other solution worked for me.

FYI, if this is the same issue I ran into, seems mine was solved by changing any one of the port-forwards (usually 8080 to 8081). Usually when'd I'd restart my host, it'd go away, so it was just a temp thing to avoid a restart. (in case that helps anyone)

Related to #391. Closing.

Another possible cause of this issue (which I just ran into): if /Applications is world-writable then VirtualBox will refuse to start the vm apparently.

I was getting this error (ssh_exchange_identification: Connection closed by remote host) because denyhosts had blacklisted my host IP for some reason. I logged in to the guest using the VirtualBox GUI console, uninstalled the denyhosts package, and commented out the line denying my host in /etc/hosts.deny.

Having the same issue when vagrant up or ssh with errors (Warning: Remote connection disconnect. Retrying...) and (ssh_exchange_identification: Connection closed by remote host) with Ubuntu 15.10.

To fix:

  1. Open VirtualBox and GUI
  2. If server is not started start it manually
  3. mv /etc/network/interfaces.d/eth0.cfg /etc/network/interfaces.d/NEW_INTERFACE_NAME.cfg
  4. change eth0 to NEW_INTERFACE_NAME in .cfg

You can get NEW_INTERFACE_NAME ifconfig -a

vagrant destroy
vagrant up
it works!

@NatsuDragnel works for me!

You don't need to destroy, I just rebooted the machine:
vagrant halt
vagrant up
vagrant ssh
And it worked for me. I had this issue probably because I messed around with my ssh keys and I guess since the machine was already running it saved previous keys.

I encountered the same issue and found that I had a settings in ~/.ssh/config that were used for ALL connections. I was behind a proxy and required something like the following for all outbound connections. Completely forgot this would also be applied to local connections e.g;

Host *
    ProxyCommand ...
    ServerAliveInterval 10

This setting was attempting to make all connections run through the proxy - which is incorrect for local connections. Anyway, that brain fart moment was fixed and I was able to SSH into boxes again.

My virtualbox is 5.1.2 and vagrant is 1.8.5 in redhat 6.5:

I just: vagrant reload ==> vagrant up ==> vagrant ssh
This worked for me.

I hope this can help.

virtualbox - 4.3.38 and vagrant - 1.2.6
vagrant halt -> vagrant up -> vagrant ssh works.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings