How To Use Putty with an SSH Private Key Generated by OpenSSH

I have access to a remote server where I am only allowed to login via SSH with a key, and I can’t add an extra key by myself, as described in “No Password SSH” post. The private key (RSA) has been generated with ssh-keygen in Linux, and I can login from Linux without issue.

This morning, I wanted to do the same with Putty in Windows XP, so I just copied the private key to Windows and loaded it in Putty, but it failed:


After a few minutes of research, I found my answer on UbuntuForums, and the reason it fails is because Putty does not support openssh keys, but uses its own format.

Here’s what I had to do:

  1. Convert OpenSSH private key to Putty private key with Putty Key Generator (puttygen)
    Start puttygen, and click on Conversions->Import key, then click Browse and select the private key generated with openssh (e.g. id_rsa).
    Then click on Save private key (e.g. id_rsa_putty.ppk)
  2. Putty SSH login with private key.
    Now you can start Putty, enter the machine IP address or url as usual, then go to Connection->SSH->Auth.
    Click Browse, and select your private key file (e.g. id_rsa_putty.ppk), go back to Session and save the session. You should now be able to login to the server.
Support CNX Software - Donate via PayPal or become a Patron on Patreon
Advertisements
Subscribe
Notify of
guest
25 Comments
oldest
newest most voted
trackback

[…] CNXSoft: How To Use Putty with an SSH Private Key Generated by OpenSSH […]

Adrián
Adrián
6 years ago

Thank you, clear and useful !!

Bill Gaskell
Bill Gaskell
6 years ago

Awesome, worked like a charm, this was driving me batty!

Jeds
Jeds
6 years ago

Thank You. I have been struggling to make the openssh 2 key to work with putty until I found your post.

Agustin
Agustin
6 years ago

Hello and thank you for the step by step guide. I have an issue, though, just at the beggining. When importing the key with puttygen I get an error message “Couldn’t load private key (unexpected end of file)” and cannot continue past that point. Any ideas regarding this error? Than you in advance!

Agustin
Agustin
6 years ago

Nevermind, I just resolved it. I think the problem was that the key file name was not standard (I’m not sure yet)

Neth
Neth
6 years ago

Nice work, helped a ton!!

Kripal Kashyap
Kripal Kashyap
5 years ago

It did not work for me, i did all the same steps given above to connect to my remote server.
I am getting exception as “server refused our key “. Any suggestion is welcome.

Angelo
Angelo
5 years ago

Awesome. really useful

Zenlooks
Zenlooks
5 years ago

Thanks guys. I have a id_rsa generated on linux machine and have to use it on windows machine using psftp of putty. I followed your conversion and everything is ok now. Thanks

Steen
Steen
5 years ago

Did the job perfectly. Thanks!!

Wilian
Wilian
4 years ago

Thank a lot for this, it helped perfectly.

ILambert
ILambert
4 years ago

Fantastic, that’s a really nasty gotcha. You’d think putty could do some validation of the key on the local machine and spit back a more useful error. Oh well, thanks again for the help!

Hai
Hai
4 years ago

Thanks so much, I almost flipped out

Aksh
Aksh
4 years ago

Hey i tried with ur solution now i m getting another error like server refused the key can you help me how to solve this error and connect to server?

tk2
tk2
3 years ago

Thank you for this information.
I spent like 2 hours trying to figure out why putty wont connect.

K
K
3 years ago

Thank you .. this worked..

Anon
Anon
3 years ago

I wish this had worked. Putty is not good software.

M
M
3 years ago

Hi everyone. For those getting “server refused” errors, the second step to this process, at least on Ubuntu on Digital Ocean, is that your server needs to have the PUBLIC part of the key pasted into a file called authorized_keys which is located in the ~/.ssh/ folder. The whole key needs to go on first line and only be one line long. Finally, success!

Peter Parker
Peter Parker
3 years ago

You rock! Thanks for publishing clear and easy steps to follow. This totally worked for me.

sneha
sneha
2 years ago

Thanks a lot!! Very helpful, I was stuck with this for days and your solution resolved my issue.

Slappy
Slappy
2 years ago

Saved me! Thanks!

Octavian Nita
Octavian Nita
2 years ago

Lifesaver… right here! 😉

Thanks!

Aaron
Aaron
2 years ago

Since I didn’t see any mention of it here you can also do this from the command line on a linux system if you have putty built. If you’re trying to convert an openssh key to a putty compatible key:

Will convert the file id_rsa_openssh to a putty compatible key id_rsa_putty. You’ll need to replace the file names (id_rsa_openssh and id_rsa_putty) to match the files you’re trying to convert. If id_rsa_putty exists it will be overwritten with the converted key.

Craig
Craig
2 years ago

@Aaron
@Aaron: Good timing on your post. I’m sure I already knew this, but I had forgotten it and your post helped me fix my problem.

Advertisements