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:
Issue:
- I generated a public / private key without a passphrase using the putty key gen on windows.
- Copied id_rsa.pub and id_rsa.ppk to ~/.ssh directory on my Mac
- Ran the below command
- ssh -i id_rsa.ppk xxx@xx.xx.xx.xx
- I kept getting the dialog asking for the password. After three attempts, it would terminate with a permission denied error.
Failed attempts:
Attempt 1:
Attempt 1:
- Renamed id_rsa.ppk to id_rsa
- Ran the below commands
- chmod 600 id_rsa
- ssh -i id_rsa xxx@xx.xx.xx.xx
Attempt 2:
- Renamed id_rsa.ppk to id_rsa
- Ran the below commands
- chmod 600 id_rsa
- sudo ssh -i id_rsa xxx@xx.xx.xx.xx
and more...
Successful attempts:
- Download puttygen.exe
- Import (Conversions -> Import Key) the private key id_rsa.ppk
- Click Conversions -> Export OpenSSH Key
- Save as id_rsa.pem
- 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.
- Run the below command
- chmod 600 id_rsa.pem
- shh -i id_rsa.pem xxx@xx.xx.xx.xx
If the above does not work then do the following
- You should have id_rsa.pem and id_rsa.pub in your ~/.ssh directory
- Rename id_rsa.pub to id_rsa_old.pub
- Run the below command
- ssh-keygen -y -f id_rsa.pem > id_rsa.pub
- 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.
- 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