我在Amazon EC2上创建了一个新的linux实例,并下载了.pem文件以允许我SSH登录。

当我试图ssh与:

ssh -i myfile.pem <public dns>

我有:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'amazonec2.pem' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: amazonec2.pem
Permission denied (publickey).

在这篇文章之后,我尝试chmod +600 .pem文件,但现在当我ssh时,我只是得到

Permission denied (publickey).

我犯了什么小学生的错误? pem文件在我的主文件夹中(在macOS中)。它的权限是这样的:

-rw-------@   1 mattroberts  staff    1696 19 Nov 11:20 amazonec2.pem

当前回答

默认情况下,无论何时下载密钥文件,它都带有644个权限。

因此,每次下载新密钥时,都需要更改权限。

 chmod 400 my_file.pem

其他回答

解决这个问题的方法是将.pem文件移到apps目录中。fooapp是我的应用程序的名字。我把它直接放在那里。

对我来说,它是编辑默认安全组,以允许端口22的入站TCP流量:

Windows 10。

. 右键单击文件 . 属性—>security—>禁用继承 .现在添加->你的用户(窗口)只有“读” . 单击ok

现在它为我工作了

默认情况下,无论何时下载密钥文件,它都带有644个权限。

因此,每次下载新密钥时,都需要更改权限。

 chmod 400 my_file.pem

使用PuTTY登录。它很好,但需要几个步骤。

Get your .pem that was generated when you first made the EC2 instance. Convert the .pem file .ppk using PuttyGen since PuTTY does not read .pem. Open PuTTY and enter your Host Name which is your instance username + Public DNS (Ex. ubuntu@ec2-xxx-xxx-xxx-xxx.region.compute.amazonaws.com). Not your AWS account username. Then navigate to Connection > SSH > Auth. Then add your .ppk file. Click on Browse where it says "Private key file for authentication". Click Open and you should be able to immediately establish connection.

我使用PuTTY 0.66在Windows。