错误的密码短语3次:git不再要求密码短语

时间:2017-06-08 18:14:58

标签: git ssh ssh-agent

我想推送远程git存储库。我输了三次错误的密码短语。我创建了一个新的ssh密钥,并在存储库服务器上注册了新的公钥。 但是ssh代理不会提示输入密码。它一直在告诉我:

  

权限被拒绝(publickey)。致命:无法从远程读取   库中。

     

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

如何在ubuntu下解决这个问题?

修改

根据建议,我尝试了ssh-add

sadik@sadix:~$ cd .ssh/
sadik@sadix:~/.ssh$ ls
config  github_rsa  github_rsa.pub  id_rsa  id_rsa.pub  keys.zip  known_hosts
sadik@sadix:~/.ssh$ ssh-add 
Enter passphrase for /home/sadik/.ssh/id_rsa: 
Identity added: /home/sadik/.ssh/id_rsa (/home/sadik/.ssh/id_rsa)
sadik@sadix:~/.ssh$ 
sadik@sadix:~/.ssh$ cd
sadik@sadix:~$ cd some/git-repo/
sadik@sadix:~/some/git-repo/$ git push -u bitbucket master
Permission denied (publickey).
fatal: Could not read from remote repository.

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

我应该补充一点,这个git存储库是从github克隆的(不属于我)。我想在bitbucket上的私有存储库上推送它。 我不知道这是否会导致权限问题,但我的第一个问题是ssh没有提示密码短语。即使重启或退出也是如此。

修改

正如Jakuje所建议我输入命令GIT_SSH_COMMAND="ssh -vvv" git push -u bitbucket master以获取客户端日志。这是输出结束:

debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/sadik/.ssh/id_rsa
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/sadik/.ssh/id_dsa
debug3: no such identity: /home/sadik/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/sadik/.ssh/id_ecdsa
debug3: no such identity: /home/sadik/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/sadik/.ssh/id_ed25519
debug3: no such identity: /home/sadik/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).
fatal: Could not read from remote repository.

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

无论出于何种原因,它会搜索一个pubkey id_dsa,因此我将id_rsa复制到id_dsa并再次尝试。 现在它提示输入密码!但是......当我输入错误的密码时,它再次问我。当我输入正确的一个时,它表示许可被拒绝。

$ git push -u bitbucket master
Enter passphrase for key '/home/sadik/.ssh/id_dsa': 
Enter passphrase for key '/home/sadik/.ssh/id_dsa': 
Enter passphrase for key '/home/sadik/.ssh/id_dsa': 
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
  1. 权限有什么问题?
  2. 为什么要寻找id_dsa而不是id_rsa

2 个答案:

答案 0 :(得分:6)

事情看起来很复杂,值得重新开始:

  1. 删除〜/ .ssh 中不需要的所有密钥(如果有要保留的密钥,请考虑将其移动到其他目录)。
  2. 如果〜/ .ssh / config 存在,请检查它是否没有可疑行。
  3. 如果您使用的是 ssh-agent ,请使用ssh-add -D删除所有密钥。使用ssh-add -l检查没有密钥。如果您看到任何输出,则表示您患有this bug。注销,登录并验证ssh-add -l是否产生无输出。
  4. 运行ls -al ~/.ssh并检查那里没有密钥。
  5. 使用ssh-keygen创建新密钥。当它要求输出文件使用默认值时按Enter键,然后键入密码短语两次。
  6. 运行ls -al ~/.ssh并检查 id_rsa id_rsa.pub 是否存在。
  7. 从Bitbucket中删除现有密钥。
  8. 〜/ .ssh / id_rsa.pub 的内容添加到Bitbucket。
  9. 使用ssh -T git@bitbucket.org测试连接。如果失败,请发布ssh -vvv git@bitbucket.org
  10. 的输出
  11. 检查git命令是否有效。
  12.   

    为什么要寻找id_dsa而不是id_rsa

    SSH会尝试多个密钥,直到找到一个有效的密钥。它尝试id_rsa,密钥被拒绝,因此继续尝试id_dsa

    感谢@Leon提及 ssh-add

答案 1 :(得分:4)

  

我多次忘记密码并猜错了。所以我创建了一个新的。

我读到,因为你有一个有效的密钥,你创建了一个新密钥,你想知道为什么它不起作用。

您需要将公钥复制到服务器的authorized_keys

相关问题