I can't connect to my AWS EC2 Ubuntu server using SSH.
Every time I want to connect using SSH, it gives:
$ ssh -i key.pem ubuntu@[IP Address]
Connection closed by [IP Address] port 22
With -vvv
option:
$ 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
I try using AWS CLI with the ec2-instance-connect
command:
$ 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
and it returns with successful
{
"RequestId": "[Request ID]",
"Success": true
}
But the problem is, when I try to log in again with new SSH key, it still gives the same error.
Anyone have the same problem before? How do you solve this issue?