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

当前回答

嗯,看了你的帖子描述,我觉得你犯了两个错误:-

设置正确的私钥权限。 下面的命令将帮助您设置正确的文件权限。 Chmod 0600 mykey.pem 您试图登录的ec2用户错误。 查看您的调试日志,我认为您已经生成了一个Amazon linux实例。该实例类型的默认用户是ec2-user。如果实例是ubuntu,那么默认用户就是ubuntu。 SSH -i privatekey。pem default_ssh_user@server_ip

Note: For an Amazon Linux AMI, the default user name is ec2-user. For a Centos AMI, the default user name is centos. For a Debian AMI, the default user name is admin or root. For a Fedora AMI, the default user name is ec2-user or fedora. For a RHEL AMI, the default user name is ec2-user or root. For a SUSE AMI, the default user name is ec2-user or root. For an Ubuntu AMI, the default user name is ubuntu. Otherwise, if ec2-user and root don't work, check with the AMI provider.

来源:https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html

其他回答

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

这只是您的aws pem密钥的权限问题。

使用以下命令将pem密钥的权限更改为400即可。

chmod 400 pemkeyname.pem

如果您没有权限更改文件的权限,您可以使用sudo像下面的命令。

sudo chmod 400 pemkeyname.pem

否则,如果没有任何工作,请按照本视频更改EC2实例上的密钥。现在可以在实例上安装公共/私有密钥对。

https://youtu.be/LvLlRCrS8B4

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

Chmod 400 xyz.pem

如果是ubuntu实例,则使用:

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

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

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

Chmod 400 my_file.pem

这招奏效了。

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

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