Home > database >  Git using the wrong SSH key
Git using the wrong SSH key

Time:03-11

I was using an SSH key for github for a while, I've now switched to a new account and Git is still trying to use my old SSH key. Here's what I get when trying to push:

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

My .gitconfig file has the correct email and name.

My ~\.ssh\config file reads as follows:

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

I deleted the old key files.

When I run ssh-add -l, the only key listed is the correct one.

I also uninstalled and reinstalled Git.

Does anyone have any insights? Is there a global config file for ssh-agent somewhere or something? I have no idea what to do, the only next step I can think of is literally reinstalling Windows.

CodePudding user response:

First, make sure you are using an SSH URL:

ssh://[email protected]/<newUser>/myproject
# or
[email protected]:<newUser>/myproject

So:

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

If you were to use an HTTPS URL, then it is possible the old user name/password is cached by the credential helper (check the value of git config --global credential.helper)

  • Related