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

OpenSSH: git@github.com permission denied

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

我过去在 WSL 上成功地做到了这一点,但似乎 OpenSSH 在 PowerShell 上给我带来了麻烦。当我尝试对一个全新的存储库执行简单的推送命令时,出现以下错误:

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. 运行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 确实具有正确的 public 密钥。

  4. 已验证上面 ssh-add 吐出的 public 密钥与我添加到我的 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
...

老实说,我很困惑,没有想法。怎么回事?

尝试 set GIT_SSH_COMMANDssh -v,然后再尝试 git push
或者 through a config

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

输出将允许您检查 Git 是否在寻找正确的键。
确保您的 在您的 Powershell 会话中

OP AlexH confirms :

it was not using the right identity the first time around.
I think this had something to do with me having named my files something other than id_rsa and id_rsa.pub.
Renaming them allowed it to go through.