【问题标题】:Command line Git doesn't recognize keys generated using GitHub for Windows命令行 Git 无法识别使用 GitHub for Windows 生成的密钥
【发布时间】:2017-04-18 13:03:27
【问题描述】:

我已经为 Windows 设置了 GitHub,并使用它来创建与我的帐户相关联的 SSH 密钥。我可以在 GitHub for Windows GUI 中执行 git 操作,但是当我尝试在命令提示符中运行类似 git clone git@github.com:whatever.git 的命令时,我收到如下错误:

C:\Users\Nat\Documents\GitHub>git clone git@github.com:natdempk/whatever.git
Cloning into 'whatever'...
Permission denied (publickey).
fatal: Could not read from remote repository.

为什么在 GitHub for Windows GUI 一切正常时会发生这种情况?

【问题讨论】:

    标签: windows git github ssh


    【解决方案1】:

    当 GitHub for Windows 创建密钥时,它们被命名为 github_rsagithub_rsa.pubgit 期望密钥默认命名为 id_rsaid_rsa.pub,因此它不会从 GitHub for Windows 中找到密钥,而是给你Permission denied (publickey)。要解决此问题,您应该为 github.com 创建一个 SSH 配置文件,作为 C:\users\<username>\.ssh\config,如下所示:

    Host github.com
        HostName github.com
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/github_rsa
    

    这会通知git 在执行连接到github.com 的操作时使用生成的 GitHub for Windows 密钥。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 2016-05-24
      • 2012-03-22
      • 1970-01-01
      • 2016-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多