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?

Tarunn
  • 103
Mike F
  • 303

1 Answers1

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

wrksprfct
  • 788