在将ssh尝试到实例时关闭AWS EC2连接

问题描述 投票:9回答:5

最近我建立了一个新的EC2实例。第二天我无法通过ssh连接到我的实例。我可以在前一天连接和断开连接,我发誓我什么也没做。这是ssh调试信息:

ssh -i webserver.pem -v [email protected]
OpenSSH_5.9p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to my.elastic.ip [my.elastic.ip] port 22.
debug1: Connection established.
debug1: identity file webserver.pem type -1
debug1: identity file webserver.pem-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
debug1: SSH2_MSG_KEXINIT sent
Connection closed by my.elastic.ip

有没有办法解决这个问题?或者我应该重新安装我的实例?请帮忙,因为我需要尽快解决这个问题。非常感谢您的帮助!

我的.pem的PS权限设置为600。

ssh amazon-web-services amazon-ec2 connection ubuntu-12.04
5个回答
6
投票

检查您的安全组。确保您有一个允许流量从实例返回的出站规则。

使用默认出站规则

type: All traffic, Protocol: All, Ports: All, Destination: 0.0.0.0/0

它会工作。


67
投票

我的问题是用户名不正确。在ubuntu实例上它应该是“ubuntu”,在亚马逊实例上它应该是“ec2-user”


1
投票

(1)请检查执行ssh命令的时间,是否与放置pem键的文件夹相同。否则你应该使用“ssh -i / your_key_path /mykey.pem”。

(2)如果没有帮助。我认为您可以创建另一个密钥并通过AWS网页设置您的EC2实例。然后再试一次。


0
投票

我有这个问题,结果发现PEM文件不正确。您可以按照Amazon EC2 Key Pairs - Verifying Your Key Pair's Fingerprint中的说明进行检查:

如果您使用AWS创建密钥对,则可以使用OpenSSL工具从私钥文件生成指纹:

$ openssl pkcs8 -in path_to_private_key -inform PEM -outform DER -topk8 -nocrypt | openssl sha1 -c

如果您使用第三方工具创建了密钥对并将公钥上传到AWS,则可以使用OpenSSL工具从本地计算机上的私钥文件生成指纹:

$ openssl rsa -in path_to_private_key -pubout -outform DER | openssl md5 -c

输出应与控制台中显示的指纹相匹配。


0
投票

我有同样的问题,它给你pem私钥文件的权限问题。确保在终端中使用sudo(管理)访问运行ssh命令。

© www.soinside.com 2019 - 2024. All rights reserved.