Convert an OpenSSH key into an RSA PKCS1 format

I’m documenting this since I ran into a couple of snags while trying to convert an open SSH key (that doesn’t play well with Node) into an RSA PKCS1 format in the command line.

See this Stack Overflow post for more information and suggestions

The snippets below assume your private key file is called private.key and you’re currently in the same directory as the private key file.

The command you need is this:

ssh-keygen -p -N "" -m pem -f private.key

However, I ended up getting this error:

Permissions 0777 for 'private.key' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.

I solved this👆 issue with:

chmod 600 private.key

Then I ran into the following error:

Key has comment 'This is a comment'

I needed to remove this comment, which I did using:

ssh-keygen -c -C "" -f private.key

After these steps, the original command worked great 🎉

ssh-keygen -p -N “” -m pem -f private.key 



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store