How to get a .pem file from ssh key pair?

According to this, this command can be used:

ssh-keygen -f id_rsa -e -m pem

This will convert your public key to an OpenSSL compatible format. Your private key is already in PEM format and can be used as is (as Michael Hampton stated).

Double check if AWS isn't asking for a (X.509) certificate in PEM format, which would be a different thing than your SSH keys.


Using ssh-keygen to export the key in the .pem format worked for me.

ssh-keygen -f id_rsa.pub -m 'PEM' -e > id_rsa.pem

Then simply copy the .pem key as necessary.

For reference:

  • the -f id_rsa.pub portion indicates the input file to read from
  • -m 'PEM indicates a PEM filetype
  • the -e option indicates that the output will be exported