Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vagrant ssh cannot connect to remote host #1936

Closed
hkdobrev opened this issue Jul 16, 2013 · 16 comments
Closed

vagrant ssh cannot connect to remote host #1936

hkdobrev opened this issue Jul 16, 2013 · 16 comments

Comments

@hkdobrev
Copy link

Here is my debug log:

https://gist.github.com/hkdobrev/6012545

The relevant part:

DEBUG virtualbox_4_2:   - [1, "ssh", 2222, 22]
DEBUG ssh: Checking key permissions: /home/hkdobrev/.vagrant.d/insecure_private_key
 INFO ssh: Invoking SSH: ["vagrant@127.0.0.1", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentitiesOnly=yes", "-i", "/home/hkdobrev/.vagrant.d/insecure_private_key", "-o", "ForwardAgent=yes"]
ssh_exchange_identification: Connection closed by remote host

The problem occurs on both vagrant up and vagrant ssh.

When running vagrant up everything hangs and if I interupt it vagrant status shows running.

Then vagrant ssh produces the given output.


Things I have tried:

  • Uninstalled vagrant.
  • Removed ~/.vagrant.d/ (had some old files there from perviously installed vagrant 1.0.x).
  • Installed vagrant again.

Vagrant version: 1.2.3

@mitchellh
Copy link
Contributor

This honestly looks like an issue with the box, rather than Vagrant. At this point, it isn't even Vagrant because it is exec'ing to ssh. Please look into how your box is configured.

@hkdobrev
Copy link
Author

@mitchellh The same Vagrantfile, box and provisioning are working on MacOS 10.8 and the problem is occuring on Ubuntu 12.04. I don't know if the OS matters, but I am pretty sure the configuration is correct, because of that.

@hkdobrev
Copy link
Author

@mitchellh I hope I don't bother you very much, but I really need some kind of a clue how to fix this.

I've just noticed the host for the ssh command is 127.0.0.1.

But in the Vagrantfile I have 192.168.33.10.

Here is it:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "cl_debian_7"

  config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box"

  config.vm.network :private_network, ip: "192.168.33.10"

  config.vm.synced_folder Dir.pwd, "/vagrant", :nfs => true

  config.ssh.forward_agent = true

  config.vm.provider :virtualbox do |vb|
    vb.customize [
      "modifyvm", :id,
      "--name", "Cain",
      "--memory", "1024",
      "--rtcuseutc", "on"
    ]
  end
  config.vm.provision :shell, :path => "provision/install.sh"
end

Unfortunately when I try to ssh manually into the VM it is not working no matter the host IP.

@mitchellh
Copy link
Contributor

Vagrant always attempts to connect using a forwarded port, not the private network, s it will always use 127.0.0.1.

Again, if you can't get SSH to work manually, then I can't really help with the Vagrant side because it is probably not a Vagrant issue. Once you can SSH in manually using the same methods as Vagrant (run vagrant ssh-config), then I can help more.

@cedricpinson
Copy link

I have the same problem, the box is a precise not modified. I tried manually to connect and nothing happen.

INFO ssh: Invoking SSH: ["vagrant@127.0.0.1", "-p", "2222", "-o", "DSAAuthentication=yes", "-o", "LogLevel=FATAL", "-o", "Stri
ctHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-o", "IdentitiesOnly=yes", "-i", "/root/.vagrant.d/insecure_priva
te_key", "-o", "ForwardAgent=yes"]
ssh_exchange_identification: Connection closed by remote host

any clue how to dig this issue ?

https://www.dropbox.com/s/9wvw91hztc2c59v/logs.zip

@pierot
Copy link

pierot commented Oct 23, 2013

I have the same issue as described above.
Scenario:

  • I create a box with vagrant up
  • I run an ansible provision against it, with success. I can login via ssh username@127.0.0.1 -p 2222 and vagrant ssh.
  • I can run the provison again and again, all with success.
  • I halt the box vagrant halt
  • I restart the box vagrant up
  • I rerun the provisioning vagrant provision --provision-with ansible. Result:
[default] Running provisioner: ansible...

PLAY [apply common configuration to all nodes] ********************************

GATHERING FACTS ***************************************************************
<127.0.0.1> ESTABLISH CONNECTION FOR USER: vagrant
<127.0.0.1> EXEC ['ssh', '-tt', '-q', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/Volumes/data/Users/pieterm/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'Port=2222', '-o', 'IdentityFile=/Users/pieterm/.vagrant.d/insecure_private_key', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=vagrant', '-o', 'ConnectTimeout=10', '127.0.0.1', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-1382558567.55-91489304099780 && chmod a+rx $HOME/.ansible/tmp/ansible-1382558567.55-91489304099780 && echo $HOME/.ansible/tmp/ansible-1382558567.55-91489304099780'"]
<127.0.0.1> REMOTE_MODULE setup
fatal: [127.0.0.1] => failed to transfer file to /home/vagrant/.ansible/tmp/ansible-1382558252.8-58387873147592/setup:

Connection closed

TASK: [import iptable rules] **************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
  • I can, however, login with ssh username@127.0.0.1 -p 2222 and vagrant ssh.

vagrant ssh-config results in

Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/pieterm/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

@dgem
Copy link

dgem commented Nov 28, 2013

For those having an issue, as @mitchellh says it may well be a problem with the box, rather than vagrant.
In my own case I ran tasksel in a ubuntu box and deselected ssh server, and when it rebooted I got the error:

ssh_exchange_identification: Connection closed by remote host

Luckily if you start the box using VirtualBox manager you can login to the console (user and password vagrant) and I was able to reinstall the missing packages, performed a reboot et vola, it all worked...

Strongly suggest you login via VB/VM console and have a wander, you may find the ssh server didn't start or some other error that prevented the vagrant ssh from working

@pierot
Copy link

pierot commented Nov 29, 2013

The solution for me was the following setting in ansible.cfg
[ssh_connection] scp_if_ssh = True

It was probably due to a box I used.

@cyenugu
Copy link

cyenugu commented Feb 13, 2014

Encountered the same issue and later realized that virtualization is not enabled on the host machine.

@cstewart87
Copy link

@cyenugu I'm curious, how do you determine if virtualization is enabled or not on the host machine?

@hkdobrev Were you able to resolve your issues?

@pleerock
Copy link

pleerock commented Mar 3, 2014

@cstewart87 you can determine if virtualization is enabled on your computer's BIOS

@skeggse
Copy link

skeggse commented Jun 20, 2014

For reference, this happened to me because I mistakenly tried to add ssh forwarding via packer by appending the Defaults env_keep += "SSH_AUTH_SOCK" to the /etc/ssh/ssh_config file instead of /etc/sudoers file, resulting in an ssh syntax error that caused sshd to fail to start.

@alberto56
Copy link

I'm using a CoreOS box, and I often log into my clients' or my own VPN (virtual private network). This generally does not cause any issues, but once in awhile I suspect that it is causing SSH to stop working. My solution is to halt and restart the machine. See below for my output:

$ vagrant ssh
ssh_exchange_identification: Connection closed by remote host
$ vagrant halt
==> core-01: Attempting graceful shutdown of VM...
    core-01: Guest communication could not be established! This is usually because
    core-01: SSH is not running, the authentication information was changed,
    core-01: or some other networking issue. Vagrant will force halt, if
    core-01: capable.
==> core-01: Forcing shutdown of VM...
$ vagrant up
Bringing machine 'core-01' up with 'virtualbox' provider...
==> core-01: Checking if box 'coreos-alpha' is up to date...
==> core-01: Clearing any previously set forwarded ports...
==> core-01: Fixed port collision for 22 => 2222. Now on port 2200.
==> core-01: Clearing any previously set network interfaces...
==> core-01: Preparing network interfaces based on configuration...
    core-01: Adapter 1: nat
    core-01: Adapter 2: hostonly
==> core-01: Forwarding ports...
    core-01: 22 => 2200 (adapter 1)
==> core-01: Running 'pre-boot' VM customizations...
==> core-01: Booting VM...
==> core-01: Waiting for machine to boot. This may take a few minutes...
    core-01: SSH address: 127.0.0.1:2200
    core-01: SSH username: core
    core-01: SSH auth method: private key
    core-01: Warning: Connection timeout. Retrying...
==> core-01: Machine booted and ready!
==> core-01: Setting hostname...
==> core-01: Configuring and enabling network interfaces...
==> core-01: Exporting NFS shared folders...
==> core-01: Preparing to edit /etc/exports. Administrator privileges will be required...
Password:
==> core-01: Mounting NFS shared folders...
==> core-01: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> core-01: flag to force provisioning. Provisioners marked to run always will still run.
$ vagrant ssh
Last login: Wed Jul 29 17:30:06 2015 from 10.0.2.2
CoreOS alpha (752.1.0)
core@core-01 ~ $ 

@hassanamirkhan
Copy link

I have the same issue.

  1. vagrant ssh works with "hashicorp/precise32" box on windows 7
  2. vagrant ssh gives me "ssh_exchange_identification: Connection closed by remote host" error with "ubuntu/trusty64" box on windows 7

Any solution ?

... DEBUG virtualbox_5_0: - [1, "ssh", 2222, 22] DEBUG virtualbox_5_0: - [1, "tcp8000", 8000, 80] INFO ssh: Attempting SSH connection... INFO ssh: Attempting to connect to SSH... INFO ssh: - Host: 127.0.0.1 INFO ssh: - Port: 2222 INFO ssh: - Username: vagrant INFO ssh: - Password? false INFO ssh: - Key Path: ["C:/Users/hkpc/.vagrant.d/insecure_private_key"] DEBUG ssh: == Net-SSH connection debug-level log START == DEBUG ssh: D, [2015-11-21T20:36:05.004327 #10680] DEBUG -- net.ssh.transport.session[1566c60]: establishing connection to 127.0.0.1:2222 D, [2015-11-21T20:36:05.012328 #10680] DEBUG -- net.ssh.transport.session[1566c60]: connection established I, [2015-11-21T20:36:05.016829 #10680] INFO -- net.ssh.transport.server_version[1574c7c]: negotiating protocol version

DEBUG ssh: == Net-SSH connection debug-level log END ==
INFO retryable: Retryable exception raised: #<Timeout::Error: execution expired>
INFO ssh: Attempting to connect to SSH...
INFO ssh: - Host: 127.0.0.1
INFO ssh: - Port: 2222
INFO ssh: - Username: vagrant
INFO ssh: - Password? false
INFO ssh: - Key Path: ["C:/Users/hkpc/.vagrant.d/insecure_private_key"]
DEBUG ssh: == Net-SSH connection debug-level log START ==
DEBUG ssh: D, [2015-11-21T20:36:20.035736 #10680] DEBUG -- net.ssh.transport.session[1d7b784]: establishing connection to 127.0.0.1:2222
D, [2015-11-21T20:36:20.045237 #10680] DEBUG -- net.ssh.transport.session[1d7b784]: connection established
I, [2015-11-21T20:36:20.054238 #10680] INFO -- net.ssh.transport.server_version[1d7f7bc]: negotiating protocol version

DEBUG ssh: == Net-SSH connection debug-level log END ==
INFO retryable: Retryable exception raised: #<Timeout::Error: execution expired>
INFO ssh: Attempting to connect to SSH...
INFO ssh: - Host: 127.0.0.1
INFO ssh: - Port: 2222
INFO ssh: - Username: vagrant
INFO ssh: - Password? false
INFO ssh: - Key Path: ["C:/Users/hkpc/.vagrant.d/insecure_private_key"]
DEBUG ssh: == Net-SSH connection debug-level log START ==
DEBUG ssh: D, [2015-11-21T20:36:35.071145 #10680] DEBUG -- net.ssh.transport.session[1df424c]: establishing connection to 127.0.0.1:2222
D, [2015-11-21T20:36:35.081647 #10680] DEBUG -- net.ssh.transport.session[1df424c]: connection established
I, [2015-11-21T20:36:35.089648 #10680] INFO -- net.ssh.transport.server_version[1dfb530]: negotiating protocol version

DEBUG ssh: == Net-SSH connection debug-level log END ==
INFO retryable: Retryable exception raised: #<Timeout::Error: execution expired>
INFO ssh: Attempting to connect to SSH...
INFO ssh: - Host: 127.0.0.1
INFO ssh: - Port: 2222
INFO ssh: - Username: vagrant
INFO ssh: - Password? false
INFO ssh: - Key Path: ["C:/Users/hkpc/.vagrant.d/insecure_private_key"]
DEBUG ssh: == Net-SSH connection debug-level log START ==
DEBUG ssh: D, [2015-11-21T20:36:50.106055 #10680] DEBUG -- net.ssh.transport.session[1e61d10]: establishing connection to 127.0.0.1:2222
D, [2015-11-21T20:36:50.116556 #10680] DEBUG -- net.ssh.transport.session[1e61d10]: connection established
I, [2015-11-21T20:36:50.125057 #10680] INFO -- net.ssh.transport.server_version[1e60864]: negotiating protocol version

DEBUG ssh: == Net-SSH connection debug-level log END ==
INFO retryable: Retryable exception raised: #<Timeout::Error: execution expired>
INFO ssh: Attempting to connect to SSH...
INFO ssh: - Host: 127.0.0.1
INFO ssh: - Port: 2222
INFO ssh: - Username: vagrant
INFO ssh: - Password? false
INFO ssh: - Key Path: ["C:/Users/hkpc/.vagrant.d/insecure_private_key"]
DEBUG ssh: == Net-SSH connection debug-level log START ==
DEBUG ssh: D, [2015-11-21T20:37:05.144464 #10680] DEBUG -- net.ssh.transport.session[1ea0bd8]: establishing connection to 127.0.0.1:2222
D, [2015-11-21T20:37:05.153965 #10680] DEBUG -- net.ssh.transport.session[1ea0bd8]: connection established
I, [2015-11-21T20:37:05.161966 #10680] INFO -- net.ssh.transport.server_version[1ea0158]: negotiating protocol version

DEBUG ssh: == Net-SSH connection debug-level log END ==
INFO ssh: SSH not up: #<Vagrant::Errors::SSHConnectionTimeout: Vagrant timed out while attempting to connect via SSH. This usually
means that the VM booted, but there are issues with the SSH configuration
or network connectivity issues. Please try to vagrant reload or
vagrant up again.>
INFO interface: detail: Guest communication could not be established! This is usually because
SSH is not running, the authentication information was changed,
or some other networking issue. Vagrant will force halt, if
capable.
INFO interface: detail: default: Guest communication could not be established! This is usually because
default: SSH is not running, the authentication information was changed,
default: or some other networking issue. Vagrant will force halt, if
default: capable.
default: Guest communication could not be established! This is usually because
default: SSH is not running, the authentication information was changed,
default: or some other networking issue. Vagrant will force halt, if
default: capable.
...

@mathsyouth
Copy link

@alberto56 Thanks for your solution. That works for me.

@jsplink
Copy link

jsplink commented Jun 3, 2016

If you have a designated ssh port in the Vagrantfile you should compare it to the actual port vagrant is running ssh on. Sometimes with multiple instances running the port-conflict-auto-correction can cause you to mess up your configs (i.e. 2222 vs 2200).

@hashicorp hashicorp locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests