Friday, January 14, 2011

Convert OpenSSH RSA or DSA key to PEM format

RSA to PEM

First create an RSA key using OpenSSH tools:

$ ssh-keygen -t rsa

Then converted it to PEM format:

$ openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem

DSA to PEM

First create an DSA key using OpenSSH tools:

$ ssh-keygen -t dsa

Then converted it to PEM format:

$ openssl dsa -in ~/.ssh/id_dsa -outform pem > id_dsa.pem

4 comments:

  1. $ openssl dsa -in ~/.ssh/id_dsa -outform pem > id_dsa.pem

    $ diff id_dsa id_dsa.pem

    The files are identical?

    ReplyDelete
  2. The files are indeed identical. Just tried your example step for step.

    ReplyDelete
  3. Yes, they are identical because the default output format for openssl is PEM.

    ReplyDelete