无法连接到远程AWS服务器

时间:2019-05-07 15:40:22

标签: amazon-web-services amazon-ec2 server

我正在尝试从Windows7计算机连接到AWS EC2实例,但出现以下错误。 与服务器的连接由远程主机关闭。 请帮我修复它。

λ ssh -i "MyLinuxKey.pem" ec2-user@ec2-13-127-91-20.ap-south-1.compute.amazonaws.com
Last login: Tue May  7 15:31:41 2019 from 157.45.50.152

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
10 package(s) needed for security, out of 16 available
Run "sudo yum update" to apply all updates.
[ec2-user@ip-172-31-6-206 ~]$ Connection to ec2-13-127-91-20.ap-south-1.compute.amazonaws.com closed by remote host.
Connection to ec2-13-127-91-20.ap-south-1.compute.amazonaws.com closed.

PUTTY-LOGS:::
2019-05-13 23:44:52 ----- Session restarted -----
2019-05-13 23:44:52 Looking up host "ec2-13-235-9-176.ap-south-1.compute.amazonaws.com" for SSH connection
2019-05-13 23:44:52 Connecting to 13.235.9.176 port 22
2019-05-13 23:44:52 We claim version: SSH-2.0-PuTTY_Release_0.71
2019-05-13 23:44:52 Remote version: SSH-2.0-OpenSSH_7.4
2019-05-13 23:44:52 Using SSH protocol version 2
2019-05-13 23:44:52 No GSSAPI security context available
2019-05-13 23:44:52 Doing ECDH key exchange with curve Curve25519 and hash SHA-256 (unaccelerated)
2019-05-13 23:44:52 Server also has ecdsa-sha2-nistp256/ssh-rsa host keys, but we don't know any of them
2019-05-13 23:44:52 Host key fingerprint is:
2019-05-13 23:44:52 ssh-ed25519 255 b0:77:f0:c0:15:b4:b2:99:38:45:4f:0c:bc:79:c1:df
2019-05-13 23:44:52 Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
2019-05-13 23:44:52 Initialised HMAC-SHA-256 (unaccelerated) outbound MAC algorithm
2019-05-13 23:44:52 Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
2019-05-13 23:44:52 Initialised HMAC-SHA-256 (unaccelerated) inbound MAC algorithm
2019-05-13 23:44:52 Reading key file "D:\softwares\AWS\keys\privateKey.ppk"
2019-05-13 23:44:53 Offered public key
2019-05-13 23:44:53 Offer of public key accepted
2019-05-13 23:44:53 Sent public key signature
2019-05-13 23:44:53 Access granted
2019-05-13 23:44:53 Opening main session channel
2019-05-13 23:44:53 Opened main channel
2019-05-13 23:44:53 Allocated pty
2019-05-13 23:44:53 Started a shell/command
2019-05-13 23:45:05 Remote side unexpectedly closed network connection

2 个答案:

答案 0 :(得分:0)

我接受AWS提供的使用默认安全组的提议,其中包括“ 所有流量”端口。

而且,在尝试多次连接新的ec2实例后,我才意识到我应该编辑我使用过的安全组,并手动添加到入站和出站22端口(ssh)!

通过指定您的PEM文件来连接到Linux,例如

ssh -i“ file.pem” ubuntu@x.x.x.x

Make sure your PEM file has 400 permission (chmod 400 file.pem).

答案 1 :(得分:0)

如果您使用的是PUTTY(用于SSH)​​,请确保使用“保持活动之间的秒数”设置。您可以在左侧菜单中“连接”选项下找到它。

对于“保持活动之间的秒数”,您需要提供以秒为单位的间隔(0表示关闭)。 Putty将发送网络数据包以使会话保持活动状态。

参考:https://the.earth.li/~sgtatham/putty/0.71/htmldoc/Chapter4.html#config-connection