【问题标题】:Git clone via SSH issue通过 SSH 问题进行 Git 克隆
【发布时间】:2016-11-20 06:05:42
【问题描述】:

我想通过 ssh 将一个 git 存储库克隆到我的 ubuntu,但出现以下错误:

权限被拒绝(公钥)。致命:无法从远程读取 存储库。

我的公钥已添加到代理中,并且我已经在 Windows 上使用过,但是当我在 Linux 上尝试时它不起作用。

【问题讨论】:

  • 当你迁移到 linux 时,你有没有把你的私钥放在你的 ~/.ssh 文件夹中?
  • 是的,并将其命名为:“id_rsa”。
  • 看看this answer。它允许您在与 github.com 交谈时指定要使用的特定 ssh 密钥
  • 如果您仍然遇到问题,请准确描述您是如何创建密钥的,您是如何在 git 服务器上进行设置的,以及您是如何在您所在的 linux 系统上安装它的试图运行 git。请包含您重命名文件时的旧名称和新名称。

标签: linux git ubuntu ssh clone


【解决方案1】:

每个远程git repo 都与一些登录相关联,这些登录将在远程系统上执行,以便访问 repo 目录。此登录尝试失败,因为 (a) 您的 SSH 密钥未被识别(或者,您计算机上的 SSH 代理未正确提供服务),并且 (b) 密码登录不是替代方案。

为了帮助诊断问题,请从图片中删除git。使用git remote -v 查找正在尝试的用户/主机,并尝试直接ssh 登录到该帐户。 (它会失败。) 像诊断任何类似的仅 ssh 问题一样诊断问题。一旦您能够登录,您就可以进行克隆。

【讨论】:

    【解决方案2】:

    Git 解决了 ssh(在你的情况下)或 https 的问题。通常最好使用底层命令而不是通过 Git 来调试连接问题,您将获得更好的诊断,并且可以使用普通的 ssh 调试技术。

    尝试仅使用ssh -v(在详细模式下的 ssh)连接到同一个遥控器。如果是git clone git@github.com:schwern/dotfiles.git,请尝试ssh -v git@github.com。只是用户和主机。是的,用户应该是git,Github 通过你的 ssh 密钥识别你。

    你应该得到这样的东西......

    $ ssh -v git@github.com
    OpenSSH_7.2p1, OpenSSL 1.0.2h  3 May 2016
    debug1: Reading configuration data /Users/schwern/.ssh/config
    debug1: Reading configuration data /opt/local/etc/ssh/ssh_config
    debug1: Connecting to github.com [192.30.253.113] port 22.
    debug1: Connection established.
    debug1: key_load_public: No such file or directory
    debug1: identity file /Users/schwern/.ssh/id_rsa type -1
    
    ...a whole lot of ssh looking for your ssh keys...
    
    debug1: Authentications that can continue: publickey
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /Users/schwern/.ssh/github
    debug1: Authentications that can continue: publickey
    debug1: Trying private key: /Users/schwern/.ssh/id_rsa
    debug1: Trying private key: /Users/schwern/.ssh/id_dsa
    
    ...a whole lot of trying ssh keys...
    
    debug1: No more authentication methods to try.
    Permission denied (publickey).
    

    重要的部分是它寻找和提供密钥的地方。如果您在那里没有看到您的 Github 密钥,那么您需要找出原因。如果您确实在其中看到了您的 Github 密钥,那么您应该检查它是否是 Github 认为您的密钥。

    你想看到的是这个。

    $ ssh -v git@github.com
    OpenSSH_7.2p1, OpenSSL 1.0.2h  3 May 2016
    debug1: Reading configuration data /Users/schwern/.ssh/config
    debug1: Reading configuration data /opt/local/etc/ssh/ssh_config
    debug1: Connecting to github.com [192.30.253.113] port 22.
    debug1: Connection established.
    debug1: key_load_public: No such file or directory
    debug1: identity file /Users/schwern/.ssh/id_rsa type -1
    
    ...ssh finding your keys...
    
    debug1: Authentications that can continue: publickey
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /Users/schwern/.ssh/github
    debug1: Server accepts key: pkalg ssh-rsa blen 279
    debug1: Authentication succeeded (publickey).
    Authenticated to github.com ([192.30.253.113]:22).
    
    ...Yay! You're in!...
    
    debug1: channel 0: new [client-session]
    debug1: Entering interactive session.
    debug1: pledge: network
    debug1: Requesting authentication agent forwarding.
    PTY allocation request failed on channel 0
    Hi schwern! You've successfully authenticated, but GitHub does not provide shell access.
    debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
    debug1: channel 0: free: client-session, nchannels 1
    Connection to github.com closed.
    Transferred: sent 2936, received 1796 bytes, in 0.2 seconds
    Bytes per second: sent 13380.7, received 8185.2
    debug1: Exit status 1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-16
      • 2020-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多