【问题标题】:Permission denied (publickey) - Cant push or pull with Git权限被拒绝(公钥) - 无法使用 Git 推送或拉取
【发布时间】:2015-02-12 13:33:45
【问题描述】:

Git 在推送到 Bitbucket 方面表现良好,直到最近除了 DNS 服务器设置的更改外,没有太大变化。

错误:

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

请确保您拥有正确的访问权限 并且存储库存在。

我使用 keygen 创建一个新密钥,使用 Git Bash 添加密钥(密钥已添加并接受),然后手动将密钥添加到 Bitbucket SSH。但是,它仍然产生相同的错误。

不知道出了什么问题,有没有人有同样的经历并能够提供帮助?


其他信息或故障排除尝试

  • git remote -v,一推一拉项目上市
  • ssh -T git@bitbucket.org - 错误:权限被拒绝(公钥)。
  • ssh-add -l - 错误:无法打开与您的身份验证代理的连接。
  • ssh -vT git@github.com - 以下错误

ssh -Tv git@bitbucket.org OpenSSH_6.6.1,OpenSSL 1.0.1i 2014 年 8 月 6 日

debug1: Connecting to bitbucket.org [131.103.20.167] port 22.
debug1: Connection established.
debug1: identity file /.ssh/id_rsa type -1
debug1: identity file /.ssh/id_rsa-cert type -1
debug1: identity file /.ssh/id_dsa type -1
debug1: identity file /.ssh/id_dsa-cert type -1
debug1: identity file /.ssh/id_ecdsa type -1
debug1: identity file /.ssh/id_ecdsa-cert type -1
debug1: identity file /.ssh/id_ed25519 type -1
debug1: identity file /.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<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: Server host key: RSA 97:8c /* rest of numbers */
debug1: Host 'bitbucket.org' is known and matches the RSA host key.
debug1: Found key in /.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: Roaming not allowed by server
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: /.ssh/id_rsa
debug1: Trying private key: /.ssh/id_dsa
debug1: Trying private key: /.ssh/id_ecdsa
debug1: Trying private key: /.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).


- ssh-agent -s,错误:

SSH_AUTH_SOCK=/tmp/ssh-2KEE1p8SGXPg/agent.1900; export SSH_AUTH_SOCK;
SSH_AGENT_PID=2712; export SSH_AGENT_PID;
echo Agent pid 2712;

【问题讨论】:

  • 感谢您提供准确详细的问题! ssh-add -L 的输出是否与 bitbucket 上的条目匹配?
  • DNS 更改?什么样的? host -t a github.com 是否解析为 192.30.252.129?
  • 等一下。你用的是bitbucket还是github?向 bitbucket 添加一个密钥并期望 github 知道它会有点乐观。 ;)
  • 我将我的 dns 更改为 google 服务器以测试一些东西。我还向 bitbucket 添加了密钥……不是 github……@michas,由于错误消息,无法查看是否匹配。我正在使用 bitbucket...鉴于上述错误,我认为主机是 github...我不确定它现在是否混淆了...但我很少用这台机器推/拉到 github
  • @michas 当我输入ssh-add -L 时错误提示Could not open a connection to your authentication agent。 @iltempo 确切的命令行是什么?主机...不起作用。

标签: windows git bitbucket git-bash ssh-keygen


【解决方案1】:

消息“无法打开与您的身份验证的连接”意味着没有代理正在运行(或至少无法访问)。

ssh-agent bash        # start a new agent
ssh-add               # add your key
ssh-add -L            # verify that your key is the same as on the server

ssh git@bitbucket.org             # should work now 
git clone git@bitbucket.org:xyz   # (or something like this) should work, too

【讨论】:

  • 对不起它的 github,因为我发布了错误的命令。我编辑了仍然相似的更正输出。当我启动新代理时,然后添加密钥......无法打开与身份验证代理的连接的相同错误。
  • 当我在 Git Bash 中输入上述内容时...我输入密码短语并被接受。但它说PTY allocation request failed on channel 0。以用户身份登录,然后说u can use git or hg to connect to bitbucket, shell access is disabled. connection to bitbucket.org is closed.
  • 这很好。您无法在 bitbucket 上打开交互式 shell 会话。它只允许 git(或 hg)客户端。关键是,您能够连接并回答 bitbucket。
  • 代理将启动一个新的 bash。只有在该 bash 中,代理才可用。由于您使用的是 Windows,因此您可能想使用 putty 套件中的 pagent。 (顺便说一句:您问题中ssh-agent -s 的输出不是错误,这些正是用于设置该缺失连接的连接信息。)
  • 您的问题暗示您正在使用某种代理。 ssh-agentpagent 都是众所周知的。使用代理不是强制性的,但它让生活更轻松。
【解决方案2】:

您需要运行ssh-agent 命令,然后导出运行时显示的变量。为此,您可以执行以下操作:

eval `/usr/bin/ssh-agent`

ssh-agent 命令的输出是一个有效的 shell 脚本,在执行时(也称为 evaled)将设置正确的环境变量,以便在ssh-agent 程序和使用它的其他程序之间进行通信。

只需确保在运行此命令之前终止现有的 ssh-agent 进程即可。

之后使用常用的ssh-add 命令列出和添加键,然后您的ssh 应该可以正常工作了。

【讨论】:

  • 我假设你的意思是在 git bash 中运行命令对吗?因为它在nodejs中不起作用。当我杀死代理时,它显示ssh_agent_PID not set, cannot kill agent. 当我输入 eval...full 行时,它给出的代理 PID 与ssh-agent 不同。回到节点......我仍然无法 git push 或 pull!对不起!
  • @Thinkerer 是的,这必须在类似 shell 的 bash 中运行。我不明白你在这里指的是nodenodejs。节点是否提供自己的外壳?如果是这样,那么有两件事:1)我不知道 nodejs 提供的 shell 的行为是否像 bash 2)您不能在一个 shell 中运行此命令并在另一个 shell 中具有相同的工作。 eval 命令设置环境变量,它们是特定于进程的。要终止代理,请终止名为 ssh-agent 及其 pid 的进程。顺便说一句,你为什么要从 node shell 而不是 git shell 运行 git 命令?
  • yes 节点提供了一个命令行实用程序,我通常会执行我的 git 拉取和推送操作,到目前为止它一直运行良好。我是使用 node 的新手,所以 node 和 git bash 的混合有点令人困惑。
【解决方案3】:

我知道这个答案可能不是最好的答案,但我设法通过以下步骤让它工作。 (免责声明:我仍然不知道出了什么问题)

  1. 在 Git Bash 中通过 kill PIDnumber 一个一个地杀死所有 ssh-agent 进程。不知何故,我有一个完整的代理进程列表正在运行。当我试图从我的系统中卸载 Git 时,我看到了这个 PID 列表。
  2. 从计算机上卸载 Git
  3. 从 Bitbucket 存储库中删除所有 SSH 密钥 -(通过浏览 BB 网站手动删除)
  4. 重新安装 Git 并在 Git bash 中,ssh -T git@bitbucket.org + 输入密码,以便用户登录并确认
  5. 添加了现有的 rsa_pub 密钥(我只是将 rsa_pub 文件拖到 sublime 文本中,复制密钥并将其粘贴回同一 repo 中的 bitbucket)
  6. 从 nodejs 的命令行实用程序拉取然后推送

【讨论】:

    【解决方案4】:

    这对我有用:

    1. 生成新的 SSH 密钥后 (ssh-keygen -t rsa)
    2. 并将其添加到 bitbucket 站点 (cat ~/.ssh/bitbucket.pub ...)
    3. 如果您仍然无法连接,请执行以下操作:

      1. 评估ssh-agent -s
      2. ssh-add bitbucket                    
      3. 现在再试一次

    【讨论】:

      猜你喜欢
      • 2014-02-01
      • 1970-01-01
      • 2018-10-24
      • 2014-03-18
      • 1970-01-01
      • 2018-03-05
      • 2013-02-28
      • 1970-01-01
      • 2020-01-04
      相关资源
      最近更新 更多