Ricardo Silva
Ricardo Silva

Reputation: 388

Vagrant "ssh_exchange_identification: Connection closed by remote host" after update Ubuntu guest

This is the second time this happens for me: I created a virtual Ubuntu machine using Vagrant and after run:

sudo apt-get update sudo apt-get upgrade

I got this:

    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

When I debug ssh connection, I see this:

vagrant ssh -- -vvv
OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data ~/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: /etc/ssh/ssh_config line 102: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 2222.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file ~/.vagrant/machines/default/virtualbox/private_key type -1
debug1: key_load_public: No such file or directory
debug1: identity file ~/.vagrant/machines/default/virtualbox/private_key-cert type -1
ssh_exchange_identification: Connection closed by remote host

This happened to me in Linux and happened the same on Mac OS.

Perhaps there is a bug or I am doing something wrong.

Upvotes: 5

Views: 8045

Answers (4)

Vick Swift
Vick Swift

Reputation: 3035

This is what worked for me after I got the same error.

From your terminal, navigate into the folder bearing your .vagrant directory and run the following commands:

 $ vagrant destroy

 $ vagrant up

 $ vagrant ssh

And you should be back up and running. Happy coding!

Upvotes: -4

Ryderpro
Ryderpro

Reputation: 1315

I ran into this issue with laravel/homestead 1.0.1 box on OSX 10.11.6 and Vagrant 1.9.1.

Turn on "Cable Connected" on your adapter in Virtual Box VM settings.

Virtual Box GUI>VM Settings>Network>Adapter> ☑ Cable Connected

To permanently fix this... Add this in the middle of your vagrantfile.

config.vm.provider 'virtualbox' do |vb| vb.customize ['modifyvm', :id, '--cableconnected1', 'on'] end

Upvotes: 7

neha
neha

Reputation: 205

Following solution worked perfectly for me :

  1. Go to home directory path : sudo chmod go-w /usr/local
  2. go to project box : a) vagrant reload, b) vagrant up & c) vagrant ssh.

Upvotes: 7

Pieter
Pieter

Reputation: 1774

The ssh_exchange_identification: Connection closed by remote host might be related to changes in VirtualBox 5.0.20 regarding the handling of port-forwarding with wildcard guest addresses, which causes the connection closed issues you are having. More information about this issue:

There are 2 ways to solve this issue:

  1. Install a test build containing a fix which will set an initial .15 guest ip address
  2. Define a guest_ip value in your Vagrantfile for your forwarded_port setting (documentation).

Upvotes: 3

Related Questions