20

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?

3
  • By the way, read "Does Heartbleed affect ssh keys?". Commented May 31, 2014 at 2:10
  • 5
    (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 Commented Mar 3, 2016 at 8:21
  • "Copy password to clipboard" didn't do anything for me! Commented Apr 25, 2020 at 22:36

1 Answer 1

48

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.

Edited on 11/18/2021

4
  • 7
    Thanks. 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
    Commented Nov 2, 2016 at 14:35
  • 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
    Commented Aug 11, 2017 at 14:00
  • Funny thing - I got that "wrong password" issue as well. It seems to be showing something "else" there.
    – Fattie
    Commented Nov 26, 2018 at 7:23
  • @gef - thank you for saving me unnecessary grief and time. I wonder if this can be done on non-MacOSX machines in some way. Commented Nov 15, 2019 at 5:35

Not the answer you're looking for? Browse other questions tagged .