Git 使用了错误的 SSH 密钥

Git using the wrong SSH key

我在 github 上使用 SSH 密钥已有一段时间,现在我已经切换到一个新帐户并且 Git 仍在尝试使用我的旧 SSH 密钥。这是我尝试推送时得到的结果:

remote: Permission to ***REPO*** denied to ***OLD USERNAME***
fatal: unable to access ***REPO***: The requested URL returned error: 403

我的 .gitconfig 文件具有正确的电子邮件和名称。

我的~\.ssh\config文件内容如下:

Host github.com
  IdentityFile ~/.ssh/id_ed25519   ***The correct key***
  IdentitiesOnly yes

我删除了旧的密钥文件。

当我 运行 ssh-add -l 时,列出的唯一密钥是正确的。

我也卸载重装了Git。

有没有人有任何见解?某处或某处是否有 ssh-agent 的全局配置文件? 我不知道该怎么做,我唯一能想到的下一步就是重新安装 Windows。

首先,确保您使用的是 SSH URL:

ssh://git@github.com/<newUser>/myproject
# or
git@github.com:<newUser>/myproject

所以:

cd /path/to/local/repo
git remote -v

如果您要使用 HTTPS URL,那么旧用户 name/password 可能会被凭证助手缓存(检查 git config --global credential.helper 的值)