juan jiménez
juan jiménez

Reputation: 13

Recover SSH Key from GITHUB

I had an ssh key in git. Now that I reinstall my operating system, how can I recover my old github ssh key and put it in /home/user/.ssh/id_rsa?

I tried to generate a new password but in this case I would have to re-register my public key again in both gitlab and github, right?

Upvotes: 1

Views: 1995

Answers (1)

bk2204
bk2204

Reputation: 76439

If you don't have a backup of your old key, then it was probably lost when you reinstalled your OS, since typically doing so reformats the hard drive. GitHub wouldn't have your private key, since that's stored only on your computer. GitHub holds only the public portion of the key, which can be used to verify connections, but not to make them.

However, it's fine to simply generate a new SSH key and add it to GitHub and GitLab, removing the old key. Part of the idea behind SSH keys is that they can be rotated more easily than other types of credentials if needed.

The easiest way to do that is to run ssh-keygen -t ed25519, which will generate you a Ed25519 key, which is the preferred key form these days. You can then add it to GitHub and GitLab as normal by copying the contents of ~/.ssh/id_ed25519.pub into the web interface.

Upvotes: 2

Related Questions