【问题标题】:wrong passphrase 3 times: git doesn't ask for passphrase anymore密码错误 3 次:git 不再要求输入密码
【发布时间】:2017-11-10 14:10:40
【问题描述】:

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

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

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

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

【问题讨论】:

  • 您的密钥(公共和私有)是否在您的~/.ssh 目录中?你chmod 700 ~/.ssh了吗?
  • @Jonathan.Brink 是的,是的。在我忘记密码并多次猜错之前,它运行得非常好。所以我创建了一个新的。唯一的问题是,它不会提示输入密码。它只是用了我之前输入的错误
  • 它在上面使用了 rsa 几行,它被拒绝了。确保它确实是您为 bitbucket 设置的密钥,重新启动 ssh-agent 并重试。
  • 你看过'$git help credentials'的文档了吗?在我看来,您可能缓存了几个旧凭据,并且无法在 ~/.ssh/ 下找到它们的密钥
  • @DougCoburn 是的,我尝试重置 credential.helper(就像这里的 stackoverflow.com/a/18542920/2013672),但这似乎没有效果。

标签: git ssh ssh-agent


【解决方案1】:

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

  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_rsaid_rsa.pub 是否存在。
  7. 从 Bitbucket 中删除现有密钥。
  8. ~/.ssh/id_rsa.pub的内容添加到Bitbucket。
  9. 使用ssh -T git@bitbucket.org 测试连接。如果失败,请发布ssh -vvv git@bitbucket.org 的输出。
  10. 检查 git 命令是否有效。

为什么要寻找id_dsa 而不是id_rsa

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

感谢@Leon 提及ssh-add

【讨论】:

  • 我没有提到ssh-agent(只有ssh-add)。无论如何,你的回答更加详尽和有帮助,我将删除我的。
  • @Leon:谢谢!不过,请不要删除您的答案,将您的个人经历记录在案是件好事。我已经更新了关于 ssh-agent 与 ssh-add 的答案。
  • 谢谢。仍然不知道出了什么问题,但有时重新开始是个好主意。
  • @Sadik:感谢您的赏金。不过现在还能用吗?
  • @tom 是的,谢谢。除了您的步骤之外,我还创建了一个新目录并对其进行了 git init,并将除 git 相关文件之外的所有文件复制到新目录中。
【解决方案2】:

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

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

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

【讨论】:

  • 这就是我写"... and registered the new public key on the repository server"时的意思。根据之前的尝试,我想知道为什么命令行不要求输入密码并假设我没有访问权限。
  • 它不假设任何东西。如果您正确设置它,它应该可以工作。发布调试日志 frpm 服务器和客户端。
  • 没有太多的对错。服务器位于 bitbucket.org。我在那里没有看到任何日志。我创建了一个新的密钥对并将 pubkey 粘贴到 bitbucket。就是这样。
  • 我没有看到任何客户端日志
  • 您放入 bitbucket 的新密钥是什么? GIT_SSH_COMMAND="ssh -vvv" git push -u bitbucket master 将生成您的调试日志。
猜你喜欢
  • 1970-01-01
  • 2022-01-25
  • 2014-04-26
  • 1970-01-01
  • 1970-01-01
  • 2014-12-18
  • 2014-07-30
  • 2021-03-29
相关资源
最近更新 更多