无法连接到 AWS EC2 的 SSH

无法连接到 AWS EC2 的 SSH

我无法连接到我的 AWS EC2Ubuntu 服务器使用 SSH。

每次我想要使用 SSH 连接时,它都会给出:

$ ssh -i key.pem ubuntu@[IP Address]
Connection closed by [IP Address] port 22

-vvv选项:

$ ssh -i key.pem -vvv ubuntu@[IP Address]
OpenSSH_8.1p1, OpenSSL 1.1.1d  10 Sep 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolve_canonicalize: hostname [IP Address] is address
debug2: ssh_connect_direct
debug1: Connecting to [IP Address] [[IP Address]] port 22.
debug1: Connection established.
debug1: identity file key.pem type -1
debug1: identity file key.pem-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.8
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.8 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to [IP Address]:22 as 'ubuntu'
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
Connection closed by [IP Address] port 22

我尝试使用以下ec2-instance-connect命令使用 AWS CLI:

$ aws ec2-instance-connect send-ssh-public-key --instance-id [instance id] --instance-os-user ubuntu --availability-zone ap-southeast-1b --ssh-public-key file://key.pub

并返回成功

{
    "RequestId": "[Request ID]",
    "Success": true
}

但问题是,当我尝试使用新的 SSH 密钥再次登录时,仍然出现相同的错误。

有人遇到过同样的问题吗?你是如何解决这个问题的?

相关内容