无法使用发送给自己的私钥连接到AWS EC2(权限被拒绝:公钥)

时间:2014-03-27 10:32:35

标签: amazon-web-services ssh amazon-ec2 private-key

我知道这是一个很常见的问题,但我相信我的情况并非常见。

我有一个ubuntu AWS EC2实例,我使用Mac上的私钥访问该实例。

我希望在工作时访问,因此我将密钥放入我的Dropbox帐户并将其下载到我的工作(Windows)电脑上并放在C:/Users/[myusername]/.ssh目录中。我也是chmod 600' d。

我使用Git shell作为ssh,因为它有SSH,我现在不想安装putty。

所以我运行命令

C:\Users\[myusername]\.ssh> ssh -v -i .\key_pair.pem ubuntu@[redacted].compute.amazonaws.com

(当然使用正确的dns名称。)

这是输出:

OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to [redacted].compute.amazonaws.com [[redacted]] port 22.
debug1: Connection established.
debug1: identity file .\\key_pair.pem type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
Warning: Permanently added '[redacted].compute.amazonaws.com,[redacted]' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: C:\\Users\\[myusername]\\.ssh\\github_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: .\\key_pair.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

我确定我使用的密钥是正确的,因为它适用于我的Mac。还有什么我做错了吗?

编辑: 我注意到调试输出提到:

debug1: Offering public key: C:\\Users\\[myusername]\\.ssh\\github_rsa

它提供不相关的公钥的事实会影响身份验证吗?

1 个答案:

答案 0 :(得分:0)

.\key_pair.pem 错了。

使用 ./key_pair.pem 代替Git bash(无论你是否在Windows上都没关系)