我想使用我的亚马逊ec2实例,但面临以下错误:

Permission denied (publickey).

我已经创建了密钥对并下载了.pem文件。

考虑到:

chmod  600 pem file.

然后,这条命令

ssh -i /home/kashif/serverkey.pem  ubuntu@ec2-54-227-242-179.compute-1.amazonaws.com

但是有这样的错误:

Permission denied (publickey)

另外,我如何连接filezilla上传/下载文件?


当前回答

它是区分大小写的。

错误:SSH EC2-user@XXX.XX.XX.XX -i MyEC2KeyPair.pem

正确方法:SSH ec2-user@XXX.XX.XX.XX -i MyEC2KeyPair.pem

其他回答

这就是我解决问题的方法

ssh -i <key> ec2-user@<ec2 ip>

我也为此挣扎了一段时间,直到我发现了以下几点:

eb ssh

当你从项目目录中使用它时,没问题,没问题,你就进入了

我在Windows中使用WinSCP。它在文件资源管理器和PuTTY SSH Shell上都能很好地访问我的Amazon EC2-VPC Linux。chmod pem文件没有任何作用,因为它使用myfile。PuTTYgen将pem文件转换为ppk。

另一个可能的问题:登录ID错误

查看“使用说明”

上面的建议都很好,但我遇到的问题是我选择了一个预先制作好的实例。实例启动后,请查看使用说明。我错误地使用了私钥的登录id,而在指令中我应该使用“bitnami”(例如bitnami@domain -i key.pem)

我挣扎着同样的权限拒绝错误显然是由于

key_parse_private2: missing begin marker 

在我的情况下,原因是当前用户的ssh配置文件(~/.ssh/config)。

使用以下方法:

ssh -i ~/myKey.pem ec2-user@<IP address> -v 'exit'

初步输出结果显示:

debug1: Reading configuration data /home/ec2-user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Hostname has changed; re-reading configuration
debug1: Reading configuration data /home/ec2-user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config

…许多调试线在这里切断…

debug1: Next authentication method: publickey
debug1: Trying private key: /home/ec2-user/somekey.pem
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.

上面的第三行是实际发现问题的地方;然而,我在调试消息从底部(上面)四行,并被误导。钥匙没有问题,但我测试了一下,比较了其他配置。

我的用户ssh配置文件通过一个意外的全局设置重置主机,如下所示。第一行Host不应该是注释。

$ cat config
StrictHostKeyChecking=no
#Host myAlias
        user ec2-user
        Hostname bitbucket.org
#        IdentityFile ~/.ssh/somekey
#        IdentitiesOnly yes

Host my2ndAlias
        user myOtherUser
        Hostname bitbucket.org
        IdentityFile ~/.ssh/my2ndKey
        IdentitiesOnly yes

我希望这对其他人有帮助。