Forgot password to id_rsa

14

10

I forgot the password to my ssh. I am planning to remove the files (id_rsa, id_rsa.pub and known_hosts) in the directory and starting from scratch. I haven't been using ssh since the whole heartbleed thing and I've cleared out the stuff in the keys before but I think I did it wrong.

My question is how do I recreate the files properly and set up ssh to stop asking me for passwords when I'm connecting to git or other things?

Mike F

Posted 2014-05-31T01:29:16.600

Reputation: 143

Question was closed 2014-06-02T00:46:58.460

3(already marked as dup. so can't answer properly) OS X may well have stored your passphrase in your keychain so you don't have to enter it each time you connect to a server. Open Keychain Access, search for "id_rsa" and you should get a result with "SSH:/Users/yourname/.ssh/id_rsa" (your private key) with "Kind" listed as "Application password". You can do Edit > Copy password to clipboard to get it back. You'll be asked for your "login keychain password" – which is just the one you use to login to the Mac's user account. To change passphrase: cd ~/.ssh and ssh-keygen -f id_rsa -p – William Turrell – 2016-03-03T08:21:16.773

By the way, read "Does Heartbleed affect ssh keys?".

– Cristian Ciupitu – 2014-05-31T02:10:26.390

Answers

33

You need to remove your SSH public/private keys, recreate them, and then add your newly created public key to the servers and online services you use.

  • Remove your SSH public/private keys:

    rm ~/.ssh/id_rsa*
    
  • Recreate the keypair, choosing a new passphrase:

    ssh-keygen -t rsa -f ~/.ssh/id_rsa
    
  • Add the newly created private key to your OS X Keychain to store the passphrase and manage unlocking it automatically:

    ssh-add -K ~/.ssh/id_rsa
    
  • Copy the public key to the OS X clipboard for adding to web services like GitHub, etc.

    cat ~/.ssh/id_rsa.pub | pbcopy
    
  • Add your newly created public key to the ~/.ssh/authorized_keys file of the remote server. Be sure to ensure the correct permissions of both the remote ~/.ssh folder (700) and ~/.ssh/authorized_keys (600). You may want to investigate using ssh-copy-id to ease this process.

wrksprfct

Posted 2014-05-31T01:29:16.600

Reputation: 618

5Thanks. I didn't need to reset it, I searched for id_rsa in my OS X Keychain, and clicked the show password icon. Entered my root password & voila :) – gef – 2016-11-02T14:35:38.853

For some reason OS X was giving me the wrong password when I used the method noted in the comment. So if that happens, definitely try the actual answer as it did solve the issue for me. – CodyEngel – 2017-08-11T14:00:21.207

Funny thing - I got that "wrong password" issue as well. It seems to be showing something "else" there. – Fattie – 2018-11-26T07:23:56.303

@gef - thank you for saving me unnecessary grief and time. I wonder if this can be done on non-MacOSX machines in some way. – perennial_noob – 2019-11-15T05:35:29.040