SSH on Mac keeps asking for the private key password

If you have come here because of a dialog that keeps showing up each time you attempt to ssh on mac with or without a passphrase, maybe this will help you.

Issue:
  1. I generated a public / private key without a passphrase using the putty key gen on windows.
  2. Copied id_rsa.pub and id_rsa.ppk to ~/.ssh directory on my Mac
  3. Ran the below command
  4. ssh -i id_rsa.ppk xxx@xx.xx.xx.xx
  5. I kept getting the dialog asking for the password. After three attempts, it would terminate with a permission denied error.
Failed attempts:

Attempt 1:
  1. Renamed id_rsa.ppk to id_rsa
  2. Ran the below commands
  3. chmod 600 id_rsa
  4. ssh -i id_rsa xxx@xx.xx.xx.xx
Attempt 2:
  1. Renamed id_rsa.ppk to id_rsa
  2. Ran the below commands
  3. chmod 600 id_rsa
  4. sudo ssh -i id_rsa xxx@xx.xx.xx.xx
and more...

Successful attempts:
  1. Download puttygen.exe
  2. Import (Conversions -> Import Key) the private key id_rsa.ppk
  3. Click Conversions -> Export OpenSSH Key
  4. Save as id_rsa.pem
  5. Copy id_rsa.pem to ~/.ssh. You should now have id_rsa.pub and id_rsa.pem. You can delete the id_rsa.ppk file.
  6. Run the below command
  7. chmod 600 id_rsa.pem
  8. shh -i id_rsa.pem xxx@xx.xx.xx.xx
If the above does not work then do the following
  1. You should have id_rsa.pem and id_rsa.pub in your ~/.ssh directory
  2. Rename id_rsa.pub to id_rsa_old.pub
  3. Run the below command
  4. ssh-keygen -y -f id_rsa.pem > id_rsa.pub
  5. This should generated a new public key file i.e id_rsa.pub. If you compare id_rsa.pub and id_rsa_old.pub, you should be noticing a difference in the comment section.
  6. Repeat the above steps under "Successful attempt" above.
Hopefully this should do the trick. The steps is the same for a key with passphrase. Happy sshing!!


Comments

Popular posts from this blog

Authoritative Server - MMO

Code dependencies