繁体   English   中英

权限被拒绝(公钥)-用Git不能推入或拉出

[英]Permission denied (publickey) - Cant push or pull with Git

直到最近,除了DNS服务器设置的更改外,Git一直没有进行太多更改,因此可以很好地将其推向Bitbucket。

错误:

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

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

我使用keygen创建了一个新密钥,并使用Gi​​t 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-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

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

eval `/usr/bin/ssh-agent`

ssh-agent命令的输出是有效的shell脚本,当执行(又称为逃避)时,该脚本将设置ssh-agent程序与使用它的其他程序之间进行通信所需的正确的env变量。

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

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

我知道这个答案可能不是最好的答案,但是我设法按照以下步骤进行操作。 (免责声明:我仍然不知道出了什么问题)

  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文件拖动到升华文本,复制了密钥并将其粘贴回同一仓库中的bitbucket)
  6. 然后从nodejs的命令行实用程序中拉出

这为我工作:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM