简体   繁体   English

无法连接到 EC2 实例 SSH 或 EC2 实例

[英]Cannot connect to EC2 Instance either SSH or EC2 Instance

I got stuck when connecting to my EC2 instance.连接到我的 EC2 实例时卡住了。 I did try both SSH with.pem file or EC2 Instance Connect.我确实尝试了 SSH with.pem 文件或 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.这是通过 EC2 Instance Connect 连接时的错误文本。

在此处输入图像描述

And this is log when connecting via SSH with verbose这是通过 SSH 以详细方式连接时的日志

在此处输入图像描述

And this is the security rules for my instance这是我的实例的安全规则

在此处输入图像描述

Does anyone know solution for this case?有谁知道这种情况的解决方案? Thank in advance.预先感谢。

-- UPDATE 1-- -- 更新 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:是的,ssh 中的所有问题都在实例内部的用户名中,因此请按照以下步骤解决您的问题:

  1. go to ec2 dashboard and check what is the user name inside your instance. go 到 ec2 仪表板并检查实例内的用户名是什么。

  2. make new connect with instance and download new file ".pem" from ec2 dashboard.与实例建立新连接并从 ec2 仪表板下载新文件“.pem”。

  3. make new file and named it "config" in local machine with this path:使用以下路径在本地计算机中创建新文件并将其命名为“config”:

~/.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 它只是这样做
ssh ec2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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