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

当前回答

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

其他回答

您不是root用户,然后运行此命令

sudo chmod 400 -R myfile.pem

如果不是root用户,则执行此命令

chmod 400 -R myfile.pem

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

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

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

chmod 400 yourPrivateKey.pem

密钥文件不应该公开可见,所以使用权限400

chmod 400 keyfile.pem

如果以上命令显示权限错误使用

sudo chmod 400 keyfile.pem

现在ssh到ec2机器,如果您仍然面临这个问题,请使用ec2-user

SSH -i keyfile。pem ec2 - user@ec2 - 12 - 34 - 56 - 78. -计算- 1. - amazonaws.com

修改密钥文件的权限:

chmod 400 key-file-name.pem

有关连接到实例的信息,请参阅AWS文档:教程:开始使用Amazon EC2 Linux实例