How to reset or change the passphrase for a GitHub SSH key?

GitGithubSshSsh KeysPassphrase

Git Problem Overview


I have forgoten my passphrase in Git. How do I reset it? I found two solutions on Stack Overflow, but I want to know what process to follow to reset it or to get it.

Git Solutions


Solution 1 - Git

If you had generate a SSH-key with passphrase and then you forget your passphrase for this SSH-key,there's no way to recover it, You'll need to generate a brand new SSH keypair or switch to HTTPS cloning so you can use your GitHub password instead.

BUT,there are exceptions

If you configured your SSH passphrase with the OS X Keychain, you may be able to recover it.

  1. In Finder, search for the Keychain Access app.
  2. In Keychain Access, search for SSH.
  3. Double click on the entry for your SSH key to open a new dialog box.
  4. Keychain access dialogIn the lower-left corner, select Show password.
  5. You'll be prompted for your administrative password. Type it into the "Keychain Access" dialog box.
  6. Your password will be revealed.

Refer to Github help - How do I recover my SSH key passphrase?

Solution 2 - Git

In short there's no way to recover the passphrase for a pair of SSH keys. Why? Because it was intended this way in the first place for security reasons. The answers the other people gave you are all correct ways to CHANGE the password of your keys, not to recover them. So if you've forgotten your passphrase, the best you can do is create a new pair of SSH keys. Here's how to generate SSH keys and add it to your GitHub account.

Solution 3 - Git

You can change the passphrase for your private key by doing:

ssh-keygen -f ~/.ssh/id_rsa -p

Solution 4 - Git

Passphrases can be added to an existing key or changed without regenerating the key pair:
Note This will work if keys doesn't had a passphrase, otherwise you'll get this: Enter old passphrase: then Bad passphrase

$ ssh-keygen -p
Enter file in which the key is (/Users/tekkub/.ssh/id_rsa):
Key has comment '/Users/tekkub/.ssh/id_rsa'
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.

If your key had passphrase then, There's no way to recover the passphrase for a pair of SSH keys. In that case you have to create a new pair of SSH keys.

  1. Generating SSH keys

Solution 5 - Git

  1. Log in to your github account.
  2. Go to the "Settings" page (the "wrench and screwdriver" icon in the top right corner of the page).
  3. Go to "SSH keys" page.
  4. Generate a new SSH key (probably studying the links provided by github on that page).
  5. Add your new key using the "Add SSH key" link.
  6. Verify your new key works.
  7. Make gitub forget your old key by using the "Delete" link next to it in the list of known keys.

Solution 6 - Git

If you are using Linux/Mac then you can remove file known_hosts.

It is located at ~/.ssh/known_hosts or if you want to overwrite/remove a specific ssh host then you can edit the known_hosts file.

To see all hosts => cat ~/.ssh/known_hosts Delete know_hosts file => rm -rf ~/.ssh/known_hosts

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTech MLGView Question on Stackoverflow
Solution 1 - GitliangzrView Answer on Stackoverflow
Solution 2 - GitMetafanielView Answer on Stackoverflow
Solution 3 - GitmanojldsView Answer on Stackoverflow
Solution 4 - GitSumit SinghView Answer on Stackoverflow
Solution 5 - GitkostixView Answer on Stackoverflow
Solution 6 - GitrahulworldView Answer on Stackoverflow