首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误密码3次: git不再要求密码

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

Stack Overflow用户
提问于 2017-06-08 18:14:58
回答 2查看 4.1K关注 0票数 12

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

拒绝许可(公开密钥)致命:无法从远程存储库读取。 请确保您有正确的访问权限和存储库存在。

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

编辑

按照建议,我尝试了ssh-add

代码语言:javascript
复制
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来获取客户机日志。这是输出的结尾:

代码语言:javascript
复制
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中,然后再试一次。现在它提示输入密码!但是..。当我输入错误的密码时,它又问我一遍。当我输入正确的一个时,它表示拒绝许可。

代码语言:javascript
复制
$ 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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-16 03:15:09

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

  1. 删除您不需要的~/..ssh中的所有键(如果有您希望保留的键,请考虑将它们移到另一个目录中)。
  2. 如果存在~/..ssh/config,请检查它没有可疑的行。
  3. 如果使用ssh代理,请使用ssh-add -D删除所有密钥.检查没有使用ssh-add -l的密钥。如果您看到任何输出,那么您正在遭受这只虫子的困扰。注销、登录并验证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. 检查git命令是否有效。

为什么它要寻找id_dsa而不是id_rsa

SSH尝试几个键,直到找到一个可以工作的键为止。它尝试了id_rsa,密钥被拒绝了,所以它继续尝试id_dsa

@Leon提到ssh-add的功劳。

票数 6
EN

Stack Overflow用户

发布于 2017-06-09 08:43:10

我忘了密码,猜错了好几次。所以我创造了一个新的。

我读到,因为你有一个有效的钥匙,你创造了一个新的,你想知道为什么它不工作。

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

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44442869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档