Cannot connect to EC2 Instance either SSH or EC2 Instance

Viewed 41

I got stuck when connecting to my EC2 instance. I did try both SSH with .pem file or EC2 Instance Connect. Everything was ok in the first time. But after that, something went wrong.

I tried to terminate my instance and launch new one once. But the new instance get this error too. Too weird.

This is error text when connecting via EC2 Instance Connect.

enter image description here

And this is log when connecting via SSH with verbose

enter image description here

And this is the security rules for my instance

enter image description here

Does anyone know solution for this case? Thank in advance.

-- UPDATE 1--

Result after run Reachability Analyzer with source (gateway) and destination (instance)

enter image description here

1 Answers

yes, all problems in ssh is in the user name inside of the instance, So follow these steps to solve your problem:

  1. go to ec2 dashboard and check what is the user name inside your instance.

  2. make new connect with instance and download new file ".pem" from ec2 dashboard.

  3. make new file and named it "config" in local machine with this path :

~/.ssh/config
  1. write this code below in your config file
# Enter the alias of the ECS instance to connect to the instance by using an SSH key pair. 
Host ec2
#Enter the public IP address of the instance. 
HostName <public IP>
#Enter the port number. The default port number is 22. 
Port 22
#Enter the logon account. 
User <put the user name you found in your instance>
#Enter the address of the .pem private key file on your PC. 
IdentityFile <~/Desktop/myservice.pem>
  1. if you want to ssh it just do like this
ssh ec2
Related