【问题标题】:Permission denied to connect to Amazon EC2 using SSH at Windows 8在 Windows 8 上使用 SSH 连接到 Amazon EC2 的权限被拒绝
【发布时间】:2014-07-25 02:36:25
【问题描述】:

我开始使用 Amazon EC2 服务。我已经安装了一个 Amazon Linux 实例,设置了 PEM 文件,打开了 SSH 端口并安装了 GIT 服务。

我的本​​地环境是 Windows 8。

通过 putty 和 WinSCP,我可以毫无问题地连接。我遵循了文档并将我的 PEM 文件转换为 PPK 并且一切正常。 问题是当我尝试从本地机器执行 git push 时。当我尝试连接时,我总是收到“权限被拒绝(公钥)”。我已经使用 git bash 对 PEM 文件进行了 ssh-add,通过 GIT Bash 生成了一个自定义密钥,并将此密钥添加到 EC2 实例的密钥解析中,但没有任何效果......

如果我尝试(使用 git bash)一个 ssh -i 并指定 PEM 文件,我就有一个连接。

ssh -i c:/[PATH]/[PEM-FILE].pem ec2-user@[HOST].compute.amazonaws.com

如果我尝试不使用 -i,则没有连接。

$ ssh ec2-user@[HOST].compute.amazonaws.com
Permission denied (publickey).

以下是使用 -vT 命令的跟踪:

ssh -vT ec2-user@[HOST].compute.amazonaws.com
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Connecting to [HOST].compute.amazonaws.com [54.201.
110.48] port 22.
debug1: Connection established.
debug1: identity file [PATH]/Usuario/.ssh/identity type -1
debug1: identity file [PATH]/Usuario/.ssh/id_rsa type 1
debug1: identity file [PATH]/Usuario/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 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
debug1: Host '[HOST].compute.amazonaws.com' is known and ma
tches the RSA host key.
debug1: Found key in [PATH]/Usuario/.ssh/known_hosts:1
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: Trying private key: [PATH]/Usuario/.ssh/identity
debug1: Offering public key: [PATH]/Usuario/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: [PATH]/Usuario/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).

那么,有没有办法通过 SSH 连接而无需 -i 选项?

【问题讨论】:

    标签: windows git amazon-web-services ssh amazon-ec2


    【解决方案1】:

    经过几次尝试,我在这里找到了一篇有一些说明的文章https://serverfault.com/questions/194567/how-do-i-tell-git-for-windows-where-to-find-my-private-rsa-key

    我按照以下步骤操作:“在您拥有主目录和该目录下的 .ssh 文件夹后,您想要打开 PuTTYgen 并打开您之前创建的密钥(.ppk 文件)。一旦您的密钥打开,您想要选择转换 -> 导出 OpenSSH 密钥并将其保存到 HOME.ssh\id_rsa。在该位置获得密钥后,Git bash 将识别该密钥并使用它”

    【讨论】:

    • 早就应该了,但这是潜伏在 SO 中一段时间​​后对我有用的唯一答案。感谢分享解决方案
    【解决方案2】:

    @Everton Menonca'a 认为它很棒。事实上,它拯救了我的一天。只是为了更详细的缘故,我要提一下我的情况:

    • 在您的 PuTTYgen 中加载私有密钥(由 EC2 生成),然后从中导出 OpenSSH 密钥。
    • 将导出的文件放在所有键的主目录中。在我的情况下(Windows)是C:\Users\USERNAME\.ssh
    • 由于我有多个使用 Bash 连接的遥控器,我更新了我的 config 文件(在同一目录下),添加了额外的条目,如下所示:

      Host bitbucket.org
       IdentityFile ~/.ssh/id_rsa1
      
      Host ec2-00-00-000-00.compute-1.amazonaws.com
       IdentityFile ~/.ssh/id_rsa2
      

    就是这样

    【讨论】:

      猜你喜欢
      • 2013-05-30
      • 1970-01-01
      • 1970-01-01
      • 2015-06-20
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      相关资源
      最近更新 更多