Home > OS >  Git keeps and old SSH key and won't let me use my new one
Git keeps and old SSH key and won't let me use my new one

Time:12-22

I have a long history with git on a particular PC, so things are quite messy.

I have a fresh SSH key that I want to use with Git for Github.
Everything is setup properly, keys are generated, added to agent and to Github.

But there's one problem.
When I try to push git tells me:

enter image description here

This is not my key and I deleted all the keys and credentials that was before.

What can I do to make Git forget this key so maybe it can start using the one I newly introduced?

CodePudding user response:

This isn't SSH rejecting your key, but rather SSH asking if you accept GitHub's host key. You can find the current host keys at https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints.

The key in this message is listed at that page:

SHA256: DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU (Ed25519)

so assuming you trust https://docs.github.com, you can safely assume that SSH is connecting to the correct host and continue with the connection. If the key did not match, you would type no to abort the connection attempt.

Once you accept the host key, authenticating GitHub with you, then SSH will continue authenticating you with GitHub.

The documentation also indicates what to add to your .ssh/known_hosts file so you can avoid the initial confirmation when you connect the first time.


Sadly, most people just blindly accept whatever key the remote hosts presets, either out of laziness or because the remote host doesn't publish its host key in a secure fashion for those that would like to verify the presented key.

  • Related