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

当前回答

在Mac终端,执行“chmod 400 xyz。“Pem”并没有帮到我,它一直说拒绝许可。对于ubuntu用户,我建议

ssh-add xyz.pem SSH -i xyz。Pem ubuntu@ec2-54-69-172-118.us-west-2.compute.amazonaws.com(注意用户是ubuntu)

其他回答

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

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

在windows中,

右键单击pem文件。然后选择属性。 选择安全选项卡——>单击“高级”按钮——>禁用继承——>删除该对象的所有继承权限 点击“添加”按钮——>选择主体——>在输入框中输入用户名——>点击“检查名称”按钮——>点击“确定”——>点击“确定”——>点击“确定”——>点击“确定”

如果没有权限别忘了sudo。 Sudo SSH -i myfile。pem < < ssh_user > > @ < >

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

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

如果您是从Windows连接,请在本地计算机上执行以下步骤。

Navigate to your .pem file. Right-click on the .pem file and select Properties. Choose the Security tab. Select Advanced. Verify that you are the owner of the file. If not, change the owner to your username. Select Disable inheritance and Remove all inherited permissions from this object. Select Add, Select a principal, enter your username, and select OK. From the Permission Entry window, grant Read permissions and select OK. Click Apply to ensure all settings are saved. Select OK to close the Advanced Security Settings window. Select OK to close the Properties window. You should be able to connect to your Linux instance from Windows via SSH.

在Windows命令提示符中运行以下命令。

使用实例重置和移除显式权限。 Icacls.exe $path /reset icacls.exe $path / grant:R "$($env:USERNAME):(R)" icacls.exe $path /inheritance:r .执行以下命令,禁用继承并移除继承权限

您应该能够通过SSH从Windows连接到您的Linux实例。