Ssh – Cannot ssh to aws ec2 instance (t2-micro)

amazon ec2amazon-web-servicesssh

I am trying to ssh to my ec2 instance

ssh -i key.pem ec2-user@xxx.com -vvv

However, I am getting an error:

Connection to xxx.com closed by remote host.
Connection to xxx.com closed.

here is the log:

debug1: Trying private key: key.pem
debug3: sign_and_send_pubkey: RSA SHA256:xxx
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug1: Authentication succeeded (publickey).
Authenticated to xxx.com ([xx.xx.xx.xxx]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Requesting no-more-sessions@openssh.com
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug3: send packet: type 1
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
   #0 client-session (t3 r-1 i0/0 o0/0 fd 4/5 cc -1)

Connection to xxx.com closed by remote host.
Connection to xxx.com closed.
Transferred: sent 2240, received 1572 bytes, in 0.0 seconds
Bytes per second: sent 2975060.5, received 2087854.9
debug1: Exit status -1

Could you help me to resolve the problem?

Best Answer

The wrong user was used. The correct one for my instance is ubuntu. So,

ssh -i key.pem ubuntu@xxx.com

allowed me successfully to shh. The list of correct users for different AMI types can be found here:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connection-prereqs.html#connection-prereqs-get-info-about-instance