【问题标题】:cannot connect to github via ssh无法通过 ssh 连接到 github
【发布时间】:2015-10-21 10:34:48
【问题描述】:

我已创建密钥并将我的公钥放入我的 github 帐户。 然后,在~/.ssh 我创建了以下配置文件:

Host github
  HostName git@github.com
  IdentityFile ~/.ssh/id_rsa2.pub

当我做 ssh github

ssh: Could not resolve hostname git@github.com: nodename nor servname provided, or not known

当我这样做时ssh -T git@github.com

Permission denied (publickey).

我做错了什么? 我在我的 github 帐户中输入的公钥显示“从未使用过”。

提前谢谢你

【问题讨论】:

    标签: github ssh public-key


    【解决方案1】:

    问题是,您正在尝试使用公钥进行身份验证。私钥,例如id_rsa2 而公钥是 id_rsa2.pub,至少在默认情况下,当使用 ssh-keygen 生成时。

    由于默认ssh使用id_rsa进行识别,所以你必须使用:

    ssh -i ~/.ssh/id_rsa2 -T git@github.com
    

    ssh 配置应如下所示:

    Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa2
    

    Host 值很重要,因为这是使用配置时必须使用的值。您现在可以使用ssh github.com。如果不更改Host 行,则需要使用ssh github,但这可能会破坏其他工具。

    您也可以使用 ssh-agent。在这种情况下,您不需要创建配置,只需将密钥添加到您的 ssh-agent 和 ssh 到 github。

    ssh-add ~/.ssh/id_rsa2
    ssh -T git@github.com
    

    【讨论】:

      猜你喜欢
      • 2012-09-04
      • 2017-03-01
      • 2012-03-20
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      • 2020-05-12
      • 2021-08-28
      相关资源
      最近更新 更多