Reputation: 2847
(I am using MAC)
My id_rsa starts with
-----BEGIN OPENSSH PRIVATE KEY-----
but I expect it to starts with
-----BEGIN RSA PRIVATE KEY-----
I have send my id_rsa.pub to server administrator to get the access to server, so I don't want to generate a new key.
Is there any way that I can transfer my id_rsa which is a openssh private key to a RSA private key? (command please.)
If I can transfer, do I also need to transfer id_rsa.pub? (command please.) It seems id_rsa.pub doesn't have a header like id_rsa, so I am not sure if I should also transfer this.
Upvotes: 158
Views: 232689
Reputation: 1947
What has worked just fine for me in converting a private key to/from RSA to/from OpenSSH is simply changing the header and footer in vi
from one format to another. E.g.:
change the top from
-----BEGIN RSA PRIVATE KEY-----
to
-----BEGIN OPENSSH PRIVATE KEY-----
and the footer from
-----END RSA PRIVATE KEY-----
to
-----END OPENSSH PRIVATE KEY-----
Upvotes: -1
Reputation: 872
Some of the answers above didn't work and I actually ran into yet another problem when trying to create a RSA private key from the OpenSSH private key using ssh-keygen
command: unsupported cipher 3des-cbc
. A helpful gist for that problem can be found here: https://gist.github.com/twelve17/0449491d86158960fdb630160799ff23.
The following command worked for me to create a valid and working RSA private key from a (Putty on Windows generated) OpenSSH key using:
$ sudo apt install putty-tools
$ puttygen existing_key.ppk -o id_rsa -O private-openssh
# enter passphrase if needed
Upvotes: 1
Reputation: 1158
Upvotes: 12
Reputation: 3358
You have an OpenSSH format key and want a PEM format key. It is not intuitive to me, but the suggested way to convert is by changing the password for the key and writing it in a different format at the same time.
The command looks like this:
ssh-keygen -p -N "" -m pem -f /path/to/key
It will change the file in place, so make a backup of your current key just in case. -N ""
will set the passphrase as none. I haven't tested this with a passphrase.
The public key should be fine as is.
For full explanation of the above command, see the -m
option here: https://man.openbsd.org/ssh-keygen#m
Upvotes: 253
Reputation: 976
You can achieve this easily if you can get your hands on a linux system. I am using ubuntu 18.04 and did the following:
sudo apt update
sudo apt install putty
sudo apt install putty-tools
puttygen yourkey -O private-sshcom -o newkey
ssh-keygen -i -f newkey > newkey_in_right_format
And you are good to go
Upvotes: 6
Reputation: 533
Here's what worked for me for an in-place conversion of a key with a passphrase:
ssh-keygen -p -P "old passphrase" -N "new passphrase" -m pem -f path/to/key
Upvotes: 30