密码错误 3 次:git 不再要求输入密码

wrong passphrase 3 times: git doesn't ask for passphrase anymore

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

Permission denied (publickey). fatal: Could not read from remote repository.

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

如何在 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.

无论出于何种原因,它都会搜索公钥 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

I forgot the passphrase and guessed wrong for multiple times. So I created a new one.

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

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

事情看起来很复杂,可能值得从头开始:

  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 创建一个新密钥。当它要求输出文件使用默认值时按回车键,然后输入密码短语两次。
  6. 运行 ls -al ~/.ssh 并检查 id_rsaid_rsa.pub 是否存在.
  7. 从 Bitbucket 中删除现有密钥。
  8. ~/.ssh/id_rsa.pub的内容添加到Bitbucket.
  9. 使用 ssh -T git@bitbucket.org 测试连接。如果失败,post ssh -vvv git@bitbucket.org.
  10. 的输出
  11. 检查 git 命令是否有效。

Why is it looking for id_dsa instead of id_rsa?

SSH 会尝试多个密钥,直到找到一个可用的密钥。它尝试了id_rsa,密钥被拒绝了,所以它继续尝试id_dsa

感谢 @Leon 提及 ssh-add.