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.
-
1Change is same as add: http://stackoverflow.com/questions/3818886/how-do-i-add-a-password-to-an-openssh-private-key-that-was-generated-without-a-p – Ciro Santilli OurBigBook.com Apr 02 '15 at 08:02
6 Answers
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.
- In Finder, search for the Keychain Access app.
- In Keychain Access, search for SSH.
- Double click on the entry for your SSH key to open a new dialog box.
- Keychain access dialogIn the lower-left corner, select Show password.
- You'll be prompted for your administrative password. Type it into the "Keychain Access" dialog box.
- Your password will be revealed.
Refer to Github help - How do I recover my SSH key passphrase?
-
One of those answers in their typical circumstances.... which feel like lifesavers! Especially when Google search and Github both SCREAM at you that this is not possible! – 0xc0de Mar 02 '23 at 14:17
You can change the passphrase for your private key by doing:
ssh-keygen -f ~/.ssh/id_rsa -p

- 290,304
- 63
- 469
- 417
-
7This implies the `~/.ssh/id_rsa` is not itself encrypted, isn't it? But if it's encrypted, we're back at square one. – kostix May 03 '12 at 22:18
-
113
-
6With regards to OP's question – no, this is not helpful if you forgot your password. But if you are simply looking to reset your password, this is the way! – Ken M. Haggerty Sep 25 '16 at 14:20
-
12How can someone enter "current password" if they forgot it? Wrong solution. – Joel James Oct 26 '16 at 17:56
-
5Question title says 'reset or change' – I landed here googling a solution to simply change the password on my keys. Number of upvotes shows I'm not the only one. – panepeter Jun 26 '17 at 10:49
-
1
-
I downvoted this answer because it's not what the OP asks for. Clearly, the OP writes "I have forgoten..." and asks for a way to 'recover' access to a key without the current passphrase. – Nikos Alexandris Dec 01 '20 at 23:51
-
After changing the passphrase, this will be needed to copy ssh keys: `pbcopy < ~/.ssh/id_rsa.pub` – ms_27 Jul 16 '21 at 08:35
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.

- 13,427
- 22
- 69
- 98

- 29,318
- 8
- 40
- 67
-
2@TechMLG That's definitely the way how to do it (follow the link to the [GitHub help](https://help.github.com/articles/generating-ssh-keys))! Worked for me to setup a new SSH key file and passphrase. The OP should consider accepting. – πάντα ῥεῖ Jan 21 '13 at 21:10
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.

- 15,743
- 6
- 59
- 89
-
31This is good if the keys doesn't have a passphrase, but if they had it and you can't remember it, then this is not usefull 'cause you'll get this: `Enter old passphrase:` then `Bad passphrase.` – Metafaniel Aug 28 '12 at 14:24
- Log in to your github account.
- Go to the "Settings" page (the "wrench and screwdriver" icon in the top right corner of the page).
- Go to "SSH keys" page.
- Generate a new SSH key (probably studying the links provided by github on that page).
- Add your new key using the "Add SSH key" link.
- Verify your new key works.
- Make gitub forget your old key by using the "Delete" link next to it in the list of known keys.

- 1,048,767
- 296
- 4,058
- 3,343

- 51,517
- 14
- 93
- 176
-
-
@jürgen-k, the passphrase is used to *cryptographically encrypt* an SSH key. The whole point of doing this is that it's only possible to use the key if you know the passphrase. If there would exist a way to recover or "reset" (whatever that could mean) the password used to deceypt an encrypted material, the utility of such a cryptographic system would be close to zero. (Note that SSH is most used for remote access to servers, not for Git). TLDR: in our case the answer "it's not possible" would be useless however correct. – kostix Nov 23 '17 at 16:44
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

- 547
- 1
- 5
- 5
-
1The question talks about recovering the passphrase for the SSH key, and has nothing to do with the `known_hosts` file. – root_access Jun 14 '22 at 06:59