简体   繁体   中英

Cannot connect to EC2 Instance either SSH or EC2 Instance

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.

在此处输入图像描述

And this is log when connecting via SSH with verbose

在此处输入图像描述

And this is the security rules for my instance

在此处输入图像描述

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

-- UPDATE 1--

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

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM