【发布时间】: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.
- 权限有什么问题?
- 为什么要查找
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),但这似乎没有效果。