简体   繁体   English

使用 powershell 对 AWS EC2 的 ssh 登录失败进行故障排除

[英]Troubleshooting ssh login failure for AWS EC2 using powershell

Short problem description: I had created two new AWS EC2 server instances on Redhat Linux and Ubuntu operating system.简短的问题描述:我在 Redhat Linux 和 Ubuntu 操作系统上创建了两个新的 AWS EC2 服务器实例。 I was trying to login to it through SSH via Putty but was getting errors(detailed errors further in question).我试图通过 Putty 通过 SSH 登录它,但出现错误(详细错误有问题)。 This is just a short description.这只是一个简短的描述。

Detailed problem description: I generated a new .pem file after creating a free tier Amazon EC2(Elastic Compute Cloud) server of Ubuntu 20 OS version.详细问题描述:我在创建Ubuntu 20 OS版本的免费层Amazon EC2(弹性计算云)服务器后生成了一个新的.pem文件。 Then I have used PuttyGen software in my Windows-10 OS pc While trying to login through putty it was giving me an error as shown in the following error description, due to this I was not able to login to aws machines, I have further investigated the issue and all details of troubleshooting steps are mentioned in detailed manner in this self answered question(other suggestions/solutions are welcome).然后我在我的 Windows-10 操作系统电脑中使用了PuttyGen软件尝试通过 putty 登录时,它给了我一个错误,如下面的错误描述所示,因此我无法登录到 aws 机器,我进一步调查在这个自我回答的问题中详细提到了问题和故障排除步骤的所有细节(欢迎其他建议/解决方案)。

Error's description:错误描述:

"Server refused our key" On terminal AND "NO supported authentication method available(server sent:public ke;gssapi-with-mic)" "Server refused our key"在终端和"NO supported authentication method available(server sent:public ke;gssapi-with-mic)"

在此处输入图片说明

Initial troubleshooting:初步故障排除:

  1. My very initial thought was that it could be control M characters in .pem file OR in private key.我最初的想法是它可以控制 .pem 文件或私钥中的 M 个字符。 But when checked key looked fine.但是当检查键看起来很好。
  2. Then I thought it could be inbound rule issue, that we are NOT allowed to do ssh to aws server but NO I was wrong when I checked configuration of server I found it was fine and 22 port was there for ssh.然后我认为这可能是入站规则问题,我们不允许对 aws 服务器执行 ssh,但是当我检查服务器配置时我错了,我发现它很好,并且 ssh 有 22 端口。
  3. Then I thought if .pem file has proper permissions or not I checked and yes it was having read permissions on all users(whoever has had access to it).然后我想 .pem 文件是否具有适当的权限,我检查过,是的,它对所有用户(有权访问它的人)都具有读取权限。

Obviously nothing of above worked;显然以上都没有奏效; enough talks so coming now to actual solution now :)足够的谈话所以现在现在来实际解决方案:)

ACTUAL FIX with complete steps:带有完整步骤的实际修复:

  • Since I am using Windows 10 OS in my PC so I have thought to go for any other medium to do ssh , hence I tried SSH with powershell as follows.由于我在我的 PC 上使用 Windows 10 操作系统,所以我想使用任何其他介质来执行ssh ,因此我尝试了SSHpowershell如下。
PS E:\test> ssh -i "aws_key_generator.pem" ubuntu@singh_server_test.compute.amazonaws.com
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @
WARNING: UNPROTECTED PRIVATE KEY FILE! @ 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'aws_key_generator.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "aws_key_generator.pem": bad permission
  • Above has given me lot of confidence and shown path to me what to do next.以上给了我很大的信心,并为我指明了下一步该做什么。 I immediately checked permissions of file again (which was READ and verified as mentioned in my initial troubleshooting column above).我立即再次检查了文件的权限(如上面的初始故障排除专栏中所述,已读取并验证)。 Then I saw that other groups are present in permissions and then I removed inheritance by going to "Right click on .pem file"-->"Properties"-->"Security"-->"Advance" and disabled “Inheritance” from there.然后我看到权限中存在其他组,然后我通过"Right click on .pem file"-->"Properties"-->"Security"-->"Advance"并禁用“继承”来删除继承那里。
  • Then I only kept "admin" group with READ ONLY permissions to it and saved the properties of file.然后我只保留“admin”组对它的只读权限并保存文件的属性。
  • Again I tried to SSH from PUTTY(using private key file generated from PuttyGen mentioned in problem statement) but it failed.我再次尝试从 PUTTY SSH(使用从问题陈述中提到的 PuttyGen 生成的私钥文件)但它失败了。
  • But when I tried from powershell command(which used .pem file) it had been successful login now.但是当我尝试使用 powershell 命令(使用 .pem 文件)时,它现在已经成功登录了。
  • Then I su as root and went to /home/ubuntu/.ssh directory and checked authorized_keys file and couldn't see PUBLIC key inside it.然后我以 root 身份进入 /home/ubuntu/.ssh 目录并检查了 authorized_keys 文件,但看不到其中的 PUBLIC 密钥。
  • So I added Public key generated by PuttyGen to "authorized_keys" and saved it.所以我将PuttyGen生成的PuttyGen添加到“authorized_keys”并保存。
  • Again I tried to login to server by Putty with passing private key to it and I was successfully able to login now BINGO :)我再次尝试通过将私钥传递给 Putty 登录到服务器,现在我可以成功登录 BINGO :)

I have fixed issue with this work around fix and thought to share with all here;我已经解决了这项工作的问题,并想在这里与所有人分享; other solutions are welcomed too, cheers and Happy learning.也欢迎其他解决方案,干杯和快乐学习。

It appears that you are logging into an Ubuntu server.您似乎正在登录 Ubuntu 服务器。

For that, the username should be ubuntu , not ec2-user .为此,用户名应该是ubuntu ,而不是ec2-user

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

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