我在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

当前回答

默认权限不允许pem键。 你只需要更改权限:

Chmod 400 xyz.pem

如果是ubuntu实例,则使用:

SSH -i xyz。pem ubuntu@ec2-youraws.amazonaws.com

其他回答

SSH -i /。pem user@host-machine-IP

我想可能是因为你输入了错误的凭证 或者,您使用的是公钥而不是私钥 或者,您的端口权限是开放的ALL到ssh。这对亚马逊不利。

您需要在密钥文件(myfile.pem)上设置一些保守的权限。 试着把它改成r-------- 或400

这个错误背后可能有三个原因。

你用错钥匙了。 您的密钥没有正确的权限。你需要chmod到400。 你用错用户了。Ubuntu映像有一个用户Ubuntu, Amazon的AMI是ec2-user, debian映像有root或admin

使用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。

你可以从ASW指南中找到答案。 400通过使其仅为所有者只读来保护它。

chmod 400 mykey.pem