OpenSSH:git@github.com权限被拒绝

时间:2019-09-04 22:51:54

标签: git windows-10 openssh

我需要为其中一个项目使用PowerShell而不是WSL。我想将终端设置为使用ssh,而不是每次都输入凭据。

过去我已经在WSL上成功完成了此操作,但似乎OpenSSH在PowerShell上给我带来了麻烦。当我尝试对全新的仓库执行简单的push命令时,出现以下错误:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

这是开始变得怪异的地方...我已经按照GitHub's article on this very subject中概述的所有步骤进行了,一切都表明我很高兴。

这就是我所做的:

  1. 已检查以确保ssh-agent正在运行。是。

  2. Ran ssh -vT git@github.com。它正在使用端口22,最后我得到Hi [MyUsername]! You've successfully authenticated, but GitHub does not provide shell access.

  3. 验证ssh-add -l -E md5确实具有正确的公钥。

  4. 验证上面ssh-add吐出的公钥与我添加到GitHub帐户的公钥完全相同。

  5. 尽管执行了步骤1,但检查并确保确实找到了我的密钥。确实是(第二行):

...
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in C:\\Users\\aleks/.ssh/known_hosts:1
...

老实说,我很沮丧,没有想法。发生了什么事?

1 个答案:

答案 0 :(得分:2)

尝试并set GIT_SSH_COMMANDssh -v,然后再次尝试您的git push
through a config

git -c core.sshCommand="ssh -v" push

输出将使您能够检查Git是否在查看正确的键。
确保您在Powershell会话中使用ssh-agent is started

OP AlexH确认in the comments

  

第一次没有使用正确的身份。
  我认为这与我将文件命名为id_rsaid_rsa.pub以外的其他文件有关。
  重命名它们可以使其通过。