mitchellh / vagrant-aws

Use Vagrant to manage your EC2 and VPC instances.
MIT License
2.61k stars 574 forks source link

vagrant up failed to connect via ssh through bastion || NetSSHException #434

Open yoramshai opened 8 years ago

yoramshai commented 8 years ago

hi, while i'm running vagrant up, ec2 instance been created successfully but vagrant failed to connect over ssh. when i'm running 'vagrant ssh box' i'm managed to connect without any problem, what i'm missing ?

FYI - the ssh connection through bastion server

INFO interface: info: Waiting for instance to become "ready"... INFO interface: info: ==> admin: Waiting for instance to become "ready"... ==> admin: Waiting for instance to become "ready"... INFO retryable: Retryable exception raised: #<Fog::Errors::TimeoutError: The specified wait_for timeout (2 seconds) was exceeded> INFO retryable: Retryable exception raised: #<Fog::Errors::TimeoutError: The specified wait_for timeout (2 seconds) was exceeded> INFO retryable: Retryable exception raised: #<Fog::Errors::TimeoutError: The specified wait_for timeout (2 seconds) was exceeded> INFO retryable: Retryable exception raised: #<Fog::Errors::TimeoutError: The specified wait_for timeout (2 seconds) was exceeded> INFO run_instance: Time to instance ready: 31.573609352111816 DEBUG run_instance: Public IP 52.18.93.182 INFO interface: info: Waiting for SSH to become available... INFO interface: info: ==> admin: Waiting for SSH to become available... ==> admin: Waiting for SSH to become available... DEBUG ssh: Checking whether SSH is ready... INFO machine: Calling action: read_ssh_info on provider AWS (i-832a7e08) INFO interface: Machine: action ["read_ssh_info", "start", {:target=>:admin}] INFO runner: Preparing hooks for middleware sequence... INFO runner: 1 hooks defined. INFO runner: Running action: machine_action_read_ssh_info #Vagrant::Action::Builder:0x00000002a7cce8 INFO warden: Calling IN action: #Vagrant::Action::Builtin::ConfigValidate:0x00000002a66420 INFO warden: Calling IN action: #VagrantPlugins::AWS::Action::ConnectAWS:0x00000002a663f8 INFO connect_aws: Connecting to AWS... INFO warden: Calling IN action: #VagrantPlugins::AWS::Action::ReadSSHInfo:0x00000002a1a4d0 INFO warden: Calling OUT action: #VagrantPlugins::AWS::Action::ReadSSHInfo:0x00000002a1a4d0 INFO warden: Calling OUT action: #VagrantPlugins::AWS::Action::ConnectAWS:0x00000002a663f8 INFO warden: Calling OUT action: #Vagrant::Action::Builtin::ConfigValidate:0x00000002a66420 INFO interface: Machine: action ["read_ssh_info", "end", {:target=>:admin}] DEBUG ssh: Checking key permissions: xxxxxxxx/xxxxxxx/xxx.pem INFO ssh: Attempting SSH connection... INFO ssh: Attempting to connect to SSH... INFO ssh: - Host: 52.18.93.182 INFO ssh: - Port: 22 INFO ssh: - Username: root INFO ssh: - Password? false INFO ssh: - Key Path: ["xxxxxxxx/xxxxxxx/xxx.pem"] DEBUG ssh: == Net-SSH connection debug-level log START == DEBUG ssh: D, [2015-12-24T18:18:51.568849 #18470] DEBUG -- net.ssh.transport.session[143c5a0]: establishing connection to 52.18.93.182:22

DEBUG ssh: == Net-SSH connection debug-level log END == INFO retryable: Retryable exception raised: #<Errno::EHOSTUNREACH: No route to host - connect(2) for 52.18.93.182:22> INFO ssh: Attempting to connect to SSH... INFO ssh: - Host: 52.18.93.182 INFO ssh: - Port: 22 INFO ssh: - Username: root INFO ssh: - Password? false INFO ssh: - Key Path: ["xxxxxxxx/xxxxxxx/xxx.pem"] DEBUG ssh: == Net-SSH connection debug-level log START == DEBUG ssh: D, [2015-12-24T18:18:58.575209 #18470] DEBUG -- net.ssh.transport.session[13f4750]: establishing connection to 52.18.93.182:22

DEBUG ssh: == Net-SSH connection debug-level log END == INFO ssh: SSH not up: #<Vagrant::Errors::NetSSHException: An error occurred in the underlying SSH library that Vagrant uses. The error message is shown below. In many cases, errors from this library are caused by ssh-agent issues. Try disabling your SSH agent or removing some keys and try again.

If the problem persists, please report a bug to the net-ssh project.

mottihoresh commented 8 years ago

were you able to fix the issue?

yoramshai commented 8 years ago

Unfortunately not

canance commented 8 years ago

I'm having the same problem. The error message shown below for me is: Net::SSH::ConnectionTimeout>

gregbook commented 8 years ago

I'm having the same issue at the end of the vagrant up. Though vagrant ssh will connect perfectly.

Any news on this ?

AhmedSamy commented 8 years ago

same issue here +1

canance commented 8 years ago

@gregbook @AhmedSamy I figured out that my issue had to do with using ssh-agent. Apparently there is a known issue between ssh-agent and vagrant. The recommended fix is to kill your ssh-agent process and try again. For now I've stopped using ssh-agent with vagrant and haven't had a problem since.

gregbook commented 8 years ago

@canance thank you for the tip but I'm still facing the same issue. I killed the ssh-agent process and tried again I have the same error. I am running Vagrant 1.8.1 on OS X El Capitan.

AhmedSamy commented 8 years ago

@canance I have the same enviroment as you have, I managed to make it work finally and here what I did:

yoramshai commented 8 years ago

@canance @AhmedSamy - although I killed the ssh-agent process on the server where i'm running vagrant, i'm still facing the same issue i'm using vagrant version 1.8 on Redhat Linux WDYT ?

canance commented 8 years ago

@yoramshai Run your vagrant ssh command with this env variable to see if any of the output indicates what the problem is:

VAGRANT_LOG=debug vagrant ssh
jpaniorte commented 8 years ago

My solution:

On Vangrant File i set "vb.gui = true", so i log into using user and password.

Once inside, i check your networkconection (p.e ping -c 3 www.google.es). If not work,

1) ifstat 2) ifup enp0s3 3) repeat ping -c 3 www.google.es

if at this point, ping works, try in guest conect to vm (ssh username@localhost -p port).

For automated up networkinterfice try set ONBOOT=yes on /etc/sysconfig/network-scripts/ifcfg-enp0s3

AhmedSamy commented 8 years ago

I ran into the same issue again after downgrading vagrant to 1.7.3 everything is fine

gregbook commented 8 years ago

A few update on my side :

The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed! mkdir -p '/vagrant' Stdout from the command: Stderr from the command: bash: sudo: command not found

Vagrant 1.8.1 works fine, the problem was that sudo was not installed in the AMI I was using... I had to create a personal AMI in the end.

developez commented 8 years ago

Here with the same issue Windows 8.1, Vagrant 1.8.1.

Mainly the problem (for me) is that the shared folder is not mounted.

Killing the ssh-agent is not valid for me.

First I tried to reload the VM.

(All commands from Git Bash on Windows)

$ vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'laravel/homestead' is up to date...
... 
==> default: Mounting shared folders...
default: /var/www => C:/Users/Daniel/Documents/Development/php/homestead-2.2.1
An error occurred in the underlying SSH library that Vagrant uses.
The error message is shown below. In many cases, errors from this
library are caused by ssh-agent issues. Try disabling your SSH
agent or removing some keys and try again.

If the problem persists, please report a bug to the net-ssh project.

Then I tried to kill ssh-agent.

$ eval `ssh-agent.exe`
Agent pid 4652
$ kill -9 4652

After reloading I get the same issue.

@AhmedSamy, How do you downgrading without recreating VM?

zmt commented 8 years ago

Back to the original issue: I hit a similar problem with shell provisioner and vagrant-aws plugin. I did enough troubleshooting to figure out that somewhere in the interaction between the provisioner and provider plugins, the config.ssh.proxy_command custom configuration in the Vagrantfile is ignored/lost. The vagrant ssh works because it does use that custom config.ssh.proxy_command configuration.

I think this issue should be retitled to "support config.ssh.proxy_command (and other custom ssh config) for all vagrant subcommands, not just 'vagrant ssh'"