我想使用我的亚马逊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上传/下载文件?


当前回答

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

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

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

其他回答

对于ubuntu 12.04 LTS微实例,我必须将用户名设置为选项

ssh -i pemfile.pem -l ubuntu dns

我也有同样的问题,这很奇怪。如果你相信你所做的一切都是好的,那么请遵循以下的原则: 有时会混淆EC2实例的用户!!有时你会得到ec2-user, ubuntu, centos等等。所以检查你的用户名的机器!!

以root用户登录 SSH -i你的密钥。Pem(400权限)root@<ip> 它将抛出错误,并将提供可用的用户名。然后使用该用户登录。

这就是我解决问题的方法

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

我也犯过类似的错误

debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: xxxx.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

我的问题是,由于第3步的run-on- startup脚本上的错误,实例没有正确启动:在高级详细信息下配置实例详细信息:

我心里想的是:

# include
 https://xxxx/bootstrap.sh


实际输入的内容会破坏实例设置

# include

https://xxxx/bootstrap.sh

因此没有创建实例端的公钥

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

eb ssh

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