简体   繁体   English

无法通过 PuTTY 连接到亚马逊 EC2 实例

[英]Unable to connect to amazon EC2 instance via PuTTY

I created a new instance of Amazon EC2 in Amazon Web Services (AWS) by referring to the documentation .参考文档在 Amazon Web Services (AWS) 中创建了一个新的 Amazon EC2 实例。 I even added a SSH rule like this:我什至添加了这样的 SSH 规则:

Port: 22  
Type: SSH  
Source: <My IP address>/32

I downloaded the .pem file, converted it into .ppk file by using PuTTYGEN .我下载了.pem文件,使用PuTTYGEN将其转换为.ppk文件。 Then I added host name in PuTTY like this:然后我在 PuTTY 中添加主机名,如下所示:

ec2-user@<public_DNS>

I selected default settings , added that.ppk file to PuTTY, logged in and I got this error:我选择default settings ,将 .ppk 文件添加到 PuTTY,登录后出现此错误:

腻子错误

Even trouble shooting link didn't help me.甚至故障排除链接也没有帮助我。
I'm also getting this error in system logs:我也在系统日志中收到此错误:
img1

How can I connect to my Amazon EC2 instance via PuTTY?如何通过 PuTTY 连接到我的 Amazon EC2 实例?

Things to check when trying to connect to an Amazon EC2 instance:尝试连接到 Amazon EC2 实例时要检查的事项:

  • Security Group: Make sure the security group allows inbound access on the desired ports (eg 80, 22) for the appropriate IP address range (eg 0.0.0.0/0 ).安全组:确保安全组允许在相应 IP 地址范围(例如0.0.0.0/0 )的所需端口(例如0.0.0.0/0 )上进行入站访问。 This solves the majority of problems.这解决了大多数问题。
  • Public IP Address: Check that you're using the correct Public IP address for the instance.公共 IP 地址:检查您是否为实例使用了正确的公共 IP 地址。 If the instance is stopped and started, it might receive a new Public IP address (depending on how it has been configured).如果实例停止并启动,它可能会收到一个新的公共 IP 地址(取决于它的配置方式)。
  • VPC Configuration: Accessing an EC2 instance that is launched inside a Virtual Private Cloud (VPC) requires: VPC 配置:访问在 Virtual Private Cloud (VPC) 内启动的 EC2 实例需要:
    • An Internet Gateway互联网网关
    • A routing table connecting the subnet to the Internet Gateway将子网连接到 Internet 网关的路由表
    • NACLs (Network ACLS) that permit through-traffic允许通过流量的NACL (网络 ACLS)

If you are able to launch and connect to another instance in the same subnet, then the VPC configuration would appear to be correct.如果您能够启动并连接到同一子网中的另一个实例,则 VPC 配置似乎是正确的。

The other thing to check would be the actual configuration of the operating system on the instance itself.要检查的另一件事是实例本身上操作系统的实际配置 Some software may be affecting the configuration so that the web server / ssh daemon is not working correctly.某些软件可能会影响配置,从而导致 Web 服务器/ssh 守护程序无法正常工作。 Of course, that is hard to determine without connecting to the instance.当然,如果不连接到实例,就很难确定。

If you are launching from a standard Amazon Linux AMI, ssh would work correctly anytime.如果您从标准 Amazon Linux AMI 启动, ssh将随时正常工作。 The web server (port 80) would require installation and configuration of software on the instance, which is your responsibility to maintain. Web 服务器(端口 80)需要在实例上安装和配置软件,这由您负责维护。

Ajay,阿杰,

Try this.尝试这个。 Go to your VPC dashboard.转到您的 VPC 仪表板。 Click on Network ACLs - on the associated acl, update your Inbound Rules to allow SSH access on port22.单击网络 ACL - 在关联的 acl 上,更新您的入站规则以允许在端口 22 上进行 SSH 访问。

转到附加到实例的 vpc,然后将条目添加到路由表,其中 0.0.0.0/0 - VPC 的目标 Internet 网关 - 作为目标保存并尝试连接它。

Go to VPC --> Security Group --> Edit inbound rules --> make the ssh source ip (anywhere) then save it and try to login with your putty-client.转到 VPC --> 安全组 --> 编辑入站规则 --> 设置 ssh 源 ip(任何地方)然后保存它并尝试使用您的腻子客户端登录。 finally go back to your security group inbound rules and change the source IP from (anywhere) to (my ip) or any custom IP do you want then save it.最后回到您的安全组入站规则并将源IP从(任何地方)更改为(我的IP)或您想要的任何自定义IP然后保存它。

note: I assume that you have successfully stored and converted your private key注意:我假设您已成功存储并转换了您的私钥

  1. Security Group - This must accept traffic from your IP address安全组 - 这必须接受来自您 IP 地址的流量
    ex:前任:

    Protocol - SSH, PORT-22, IPAddress - SOME IP ALLOW协议 - SSH、PORT-22、IP 地址 - 某些 IP 允许
    All Traffic On Any Port From 0.0.0.0/0 means from any IP Address ALLOW来自 0.0.0.0/0 的任何端口上的所有流量意味着来自任何 IP 地址 ALLOW

  2. Route Table - Make Sure you have outgoing traffic route enabled路由表 - 确保已启用传出流量路由
    ex: Destination - 0.0.0.0例如:目的地 - 0.0.0.0
    target- internet gateway目标互联网网关

  3. Use or generate private key使用或生成私钥

I struggled with this problem for ages after my EC2 instance suddenly started refusing a connection.在我的 EC2 实例突然开始拒绝连接后,我为这个问题苦苦挣扎了很长时间。 I tried every answer on SO and Google but nothing helped!我在 SO 和 Google 上尝试了所有答案,但没有任何帮助!

The fix was to make sure that the Network ACL inbound rules were updated to match the rules on the security group.修复是为了确保更新网络 ACL 入站规则以匹配安全组上的规则。

I have no clue why it worked yesterday and stopped today, but this fixed it.我不知道为什么它昨天起作用而今天停止了,但这解决了它。

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

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