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

当前回答

如果您是从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实例。

其他回答

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

sudo chmod 400 -R myfile.pem

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

chmod 400 -R myfile.pem

视窗 10 - PowerShell

icacls.exe .\Desktop\xxxx.pem /reset
icacls.exe .\Desktop\xxxx.pem /grant:r "$($env:USERNAME):(r)"
icacls.exe .\Desktop\xxxx.pem /inheritance:r

ssh -i .\Desktop\xxxx.pem ec2-user@54.2xx.xxx.x

macos与linux

chmod 400 ~/Desktop/xxxx.pem

ssh -i ~/Desktop/xxxx.pem ec2-user@54.2xx.xxx.x

我的问题是我的.pem文件在我的一个NTFS分区中。我把它移动到我的linux分区(ext4)。

通过运行给予所需的权限:

Chmod 400 my_file.pem

这招奏效了。

如果你在windows 10上使用ubuntu子系统,如果你sudo chmod将密钥更改为400,那么它可能仍然会出现“Load key pem: Permission denied”的错误。

Ls -al,你会看到root现在拥有文件!咀嚼它到您的登录用户,然后它将工作。

Windows 10。

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

现在它为我工作了