SSH hangs when connecting to Amazon EC2 instance

时光毁灭记忆、已成空白 提交于 2019-12-08 17:13:41

问题


I could connect to ec2 instance with the following command, but today I couldn't connect using it.

ssh -i abcKey.pem ubuntu@ec2-x-x-x-x.ap-southeast-1.compute.amazonaws.com -v

Following is the verbose. I have opened SSH port in EC2 ( I could connect to this till yesterday)

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to ec2-x-x-x-x.ap-southeast-1.compute.amazonaws.com [x-x-x-x] port 22.
debug1: Connection established.
debug1: identity file abcKey.pem type -1
debug1: identity file abcKey.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent

回答1:


One possible problem is that the Security Group restrictions are too strict for you to be able to connect. To fix this:

  1. Go to the EC2 Management Console
  2. Click on Security Groups (in the left sidebar).
  3. Select your EC2 instance's security group.
  4. In the bottom box, click on the Inbound tab.
  5. There should be an SSH rule, make sure that it can be accessed from anywhere and that it is on the correct port (22 for SSH). Also, make sure that the protocol is TCP.



回答2:


I was having the same issue. I followed what Amazon suggested in a video for handling a hanging SSH connection attempt. No dice. What worked in my case was using the following command:

ssh -i yourKeyHere.pem ec2-user@yourPublicIPHere -v

The publicIP is listed under publicIp in the EC2 management console.




回答3:


I found I was getting stuck because my Route Table had no Internet Gateway setup.

I added an Internet Gateway, attached to my VPC, then added 0.0.0.0/0 to my Route Table targeting the Internet Gateway. This fixed this issue.



来源:https://stackoverflow.com/questions/29667729/ssh-hangs-when-connecting-to-amazon-ec2-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!