Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I tried to use putty also. I select this pem key there and got this:

Unable to use key file "key.pem" (not a private key).

I read that it is possible to convert a pem to a pub key. I did it like there:

  1. Convert pem key to ssh-rsa format

  2. How can I convert a PEM key into a RSA key pair?

But I got the same error when trying to connect.

share|improve this question
It'd probably help if you posted the "same error" you got. Also, if possible, add an excerpt of the SSH log (usually /var/log/auth.log; if you have admin privileges on the server, try to up the verbosity of SSH's logging while you're at it) to the question. Help us help you. –  Shadur Feb 14 '12 at 9:33
Also, why are you trying to do this? There's very little advantage to generating an ssh keypair from an existing key vs. just generating a new keypair. –  larsks Feb 14 '12 at 22:41
Can you provide the output of file key.pem (this is a *nix command, not windows). –  Patrick Feb 25 '12 at 4:57

3 Answers 3

The PEM format can contain more than one key. There are often more then one public keys or a key-pair concatenated together. For ssh you have a key-pair id_rsa is the private key in PEM format. id_rsa.pub is your public key.

It is not possible to convert a private key to public key, except of some brute force hacking. To connect to another host using the keys, you need to copy your public key to other host by using ssh-copy-id. The sshd server should have PubkeyAuthentication enabled.

share|improve this answer
"It is not possible to convert a private key to public key". That is not true: ssh-keygen -f ~/.ssh/id_rsa -y –  Patrick Mar 10 '14 at 3:18
Well, thats a "private OpenSSH format file" and it contains the private and the public key so you are not converting anything there. I wrote that a PEM format can contain more than one key, you just pull the other key from the file. –  user55518 Mar 10 '14 at 3:58
You should disambiguate that in your answer. The very last thing you talk about before that sentence is id_rsa and id_rsa.pub. –  Patrick Mar 10 '14 at 6:25

inside the .pem there is a section for private key, you can just take that and put it into a .key file (the other section would go in your .crt) then you have your .crt and your .key. i have no idea if you can use that .key with ssh though.. i dont see why not.. just try naming it appropriately

cat blah.key > ~/.ssh/id_rsa
cat blah.crt > ~/.ssh/id_rsa.pub

copy it to remotemachine and

cat id_rsa.pub >> ~/.ssh/authorized_keys
share|improve this answer
SSH does not use certificates, and OpenSSH .pub format is not PEM at all. It is possible to extract the pubkey from the X.509 cert with openssl as PEM and then convert it to openssh per stackoverflow.com/questions/1011572/… but since you have the private key it's much easier to just extract with ssh-keygen -y . –  dave_thompson_085 Apr 29 '14 at 9:56

(Partial answer but too many links for reasonable comment.)

putty doesn't use PEM format (like OpenSSL and OpenSSH), instead its own format PPK. Run puttygen and it can Load (or Import) private-key from PEM and Save to PPK. Partial dupe of:

Can I use an SSH key generated on Linux from Putty?

What difference between openssh key and putty key?

Convert Amazon .pem key to Putty .ppk key Linux


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.