With openssl version 1.1.1n, I used to use
openssl genrsa -out myFile.pem
and my key file would look like this:
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
However, I recently updated to Ubuntu 22.04 and now I have openssl version 3.0.2. Now when I run that command, the output file looks like this:
-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----
Notice that the "RSA
" is missing. My application now says "unsupported key format" because of this.
I tried using
openssl genpkey -algorithm RSA -out myFile.pem
because the docs for genrsa
say it's deprecated and recommend using genpkey
instead. But this gave the same results (the file is missing the "RSA
" part).
How can I properly generate an RSA key using openssl that matches the old format?
You can use
openssl genrsa -out myFile.pem -traditional
to get the right file format.
For a more backwards compatible command, you can use ssh-keygen
instead:
ssh-keygen -t rsa -m PEM -f myFile.pem -N "" <<< y
The <<< y
part will answer the "do you want to overwrite the existing file" interactive prompt.
The normal output of ssh-keygen
(which is an "OpenSSH private key") is actually supported by my application, so the -m PEM
was not necessary in my case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With