【问题标题】:Github SSH works but clone using ssh failsGithub SSH 工作,但使用 ssh 克隆失败
【发布时间】:2017-05-17 20:43:03
【问题描述】:

我在使用 ssh 克隆 git 存储库时遇到了一个奇怪的问题。我有 ssh 设置:

ssh -T git@github.com
Hi yusufali2205! You've successfully authenticated, but GitHub does not provide shell access.

我正在使用正确的克隆 URL,并且可以访问我想要克隆的存储库。但出现错误:

➤ git clone git@github.com:<some-org>/<repo>.git
Cloning into 'project'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

没有其他消息可以调试我的 ssh 设置或 git 配置有什么问题。

【问题讨论】:

    标签: git github ssh git-config


    【解决方案1】:

    我发现我的.gitconfig 中有一个条目将 ssh 替换为 https。

    [url "https"]
        insteadOf = git
    

    我可能在使用某些工具时不小心添加了此条目。所以克隆命令实际上是使用 url https@github.com:&lt;some-org&gt;/&lt;repo&gt;.git

    .gitconfig 中删除上述条目后,问题已解决。

    【讨论】:

      【解决方案2】:

      就我而言,我必须删除 ~/.ssh/known_hosts 文件,以便在克隆时重新制作该文件。在此之后,它工作了

      【讨论】:

      • 我的情况与 OP 略有不同。升级我们的 GitHub 服务器后,ssh 克隆工作正常,但 https 克隆最终会挂起并给出 404。我认为问题在于 ssh 连接正在等待用户接受服务器的新 ID。我没有删除整个文件,我只是从 known_hosts 文件中删除了我们的 GH 服务器的单个条目。
      【解决方案3】:

      我遇到了同样的问题,我在研究中尝试了一些东西,我得到了它。进入你的 .ssh 目录,用记事本打开 known_hosts 文件,它的开头有“github.com” ... 插入 SSH: 在 github.com 的开头,它看起来像这样:“SSH: github .com”并保存,然后重试。它对我有用!

      【讨论】:

        【解决方案4】:

        我遇到了同样的问题,但就我而言,这是因为我使用自定义名称(例如,my_keymy_key.pub)命名了我的密钥文件,并且没有让 ssh-keygen 使用默认名称,它们是:

        • id_rsa
        • id_dsa
        • id_ecdsa
        • id_ed25519
        • id_ed25519_sk
        • id_xmss

        如果您使用 ssh-add 添加自定义命名键(正如许多教程所说的那样),那么命令 ssh -T git@github.com 可以完美运行,但不是 git clone 命令。
        这是因为git 在使用 ssh 时只查找具有默认名称的键。

        我可以通过将以下属性添加到全局 .gitconfig 来确定这一点:

        [core]
            sshCommand = ssh -vvv
        

        当您在使用 ssh 时尝试克隆存储库(或其他 git 操作)时,它基本上会吐出所有日志消息。

        注意:我使用的是 Windows 10,这可能与 git 如何在 Windows 上工作有关。我没有在 *nix 系统上测试过。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-04-08
          • 2017-07-28
          • 2019-10-03
          • 1970-01-01
          • 1970-01-01
          • 2021-08-28
          • 2021-11-21
          • 2019-06-09
          相关资源
          最近更新 更多