Convert SSH private key with PuTTY keygen

This tutorial will show you how to convert SSH private key with Putty keygen.
It is silly, but SSH2 private keys do not have standard format. OpenSSH, ssh.com, PuTTY have different formats, and any key generated with one client cannot immediately be used with another.

For example in my tutorial create and use SSH key under linux we have discussed how to create key pair using ssh-keygen tool. My private key was looking like this:

  1. —–BEGIN RSA PRIVATE KEY—–
  2. MIIEoQIBAAKCAQEArgTgbwlQ2axj9zRF4nPa4kA55+/OHoyWd7JOlSEJuMn8H2mu
  3. RGS2msRFe0EFEr+Doq1yeugMBmIum/VUBx2PY0h6f0O9IMjPc+Cjn6xPg/fcuTQK
  4. bHVL+brfCTj4/vXefvRtPxBr7JcBxtfGa7Q4d3NKHGR9f9t2irhXiCxCPEH1UAzT
  5. GVb3JqmkHHM2ILmjvoEatfaqyCIL32EXQU1ThKzF27obb1+db4eT7R1UrznMNDFi
  6. j1mQw8epy1Ki3prTQ4m+q4jvSRPWidOheIBipQ/GkQLBCOEPKvUA5F5Mm7Lm8uR4
  7. 5ClEhm5iV/j0ikS7P27EZNq1WqsFdAWol3Ji/wtcxygVYOZ/br72WV8oqb8izOgO
  8. t0uthUKLk/I1p8DsQFqAMFS4cQ5jTXIhC7ItnO6K1ZjQD8Qcd4ILRCPQ2vYcsQN6
  9. lQi134AAyNZp+stSnpXq1jKVvII+MMLg0OLpouvlD6ZjZ5XEJ8WJfAOG1hZSeDp0
  10. HRS2Bx7Hx8kB87yNSwft4FfScNQbKAj1Y3LtdO/HbWX3KDC4Zj/D53+DFc9FKMuo
  11. GVy3EGi4z1kWR5mvdWhC+byJm4+RLVaL5yFh9wIBIwKCAQBed60JE6+MG8E9Db+J
  12. AYqEObTepNjCQ9/aFpMeFgxPtOpOF4XZyxrst0RQYOxtex7WWu14S6G0wx4cK04h
  13. IzvjAoGBAOGoisl111xEYFmedIacvFRL6Ln3/b2JT1Tht9WkqO/vFG8W3ELoh0GB
  14. 7acPf9kYpzeNY7qyKTDZkK3n1ElzQFFo7RNVq3tX9UF2cCJ3rFAwvIw/jaKlOqxL
  15. Cen9qXJ7aW1QChMkNCrAtioeBPmpHKAJAeWmy0f5pOR02Tvpjys02KmhIKKRj9Uu
  16. C96joukxDO/Yyvdjl+XLHq4hybFwKG5zXIeoUpTGow2D1cTdovMTAoGBAMVq119I
  17. u3ImbgO9F8BhFvsL+1bGwwelnFeyo5afPQnk1mdC3o9S/8CW8VGk8NGA1TW0sE5a
  18. dxjvjKfIpvSvc4F3Lla3L3ocJsV1nMtTMA4NAoGAGcoefWyNpCUSU2KQ+XD/lJr2
  19. Bp//vePOjVuf+yjC2ZeqkFpiUMoeFh16Pvp1At4+/wjYMpgEtSAtyrtot+/qF+68
  20. AjWtMqr3dTIbcasddiasdahsjdscpfnygSRN4TKs9ozODaT7arggw3GTZLxcZGT0
  21. ocoYEQDCLW4nDy9F0qMCgYAWj94ZhKe1Rjh1dLJB3zW5C3OtHValukm2IfSkk1Cs
  22. iBc7bPzm6MhenlmBR94/RZ1UaGg1ntzI/MIpR28xWpra3MxEbnywarLIMaxLum1g
  23. N2j128Gp+ttmd6aM/OhSdR+uXcsBo/BanwjCt9iQ/hvUSCKNkUdBJ8nqrlsP7EAB
  24. mwKBgQCUDdTKRs8Vyva9tBPpo+cvZ2gtvw0S5XWr2m2nI2c0ZljQlmqEtd9+1S8u
  25. DjMmaTmmP4Rpz6iCMObIuSf5PYLwx0yTr68KQ2Nunrq3ocsmpD6Oc1ZQglDs7ipq
  26. pvZKBjWEGzXZbIUU/6jL8vdLEmmwDL09chQBCN0sxtMz4NX2xQ==
  27. —–END RSA PRIVATE KEY—–

If I just copy and paste it in a file and include it when I am using PuTTY I will receive an error saying: ‘Server refused our key’

So save your key in a simple text file using Notepad. In order to have this key converted, you can use PuTTY keygen to import and save the key in appropriate format.

If you do not have PuTTY keygen tool, you may download it from http://putty.nl .
Usually it comes along with PuTTY package so if you have it installed it should be inside C:\Program Files\PuTTY .

Anyway, open it and click on ‘Conversions’ and then ‘Import key’, locate the text file you saved and open it.

Convert SSH private key with PuTTY keygen

PuTTY keygen imports such key like this:

Convert SSH private key with PuTTY keygen

Now simply click on ‘Save private key‘, choose a location and click save.
The new key will look rather different:

  1. PuTTY-User-Key-File-2: ssh-rsa
  2. Encryption: aes256-cbc
  3. Comment: imported-openssh-key
  4. Public-Lines: 4
  5. AAAAB3NzaC1yc2EAAAABIwAAAIEAqGke075QDUb3Y+fLq8xJHwYccBQwaaFvPDi6
  6. PiH4+FMTCbIwCnEBKksnfE4hhl4rdoh4f55q9k83WCHhrQ3i6ZYe8kR88iTJb6XW
  7. ai9r2j5OGrg11YRSoJzf84q2pw36N6a39kTHvQgxiZGZiFy8psfjVJ0WqjmAqJp7
  8. IR+kiX0=
  9. Private-Lines: 8
  10. WJKnS254U4y85EYNfHeyMvfJRadMsUeqIDD69GgC0xDbKkjUbGyd8bO9TmJZIziz
  11. oDDQp4bFqIhGZNrBU4b0KKw/27JnKYF79i0NT+cN7M7sWLTHGkosag4jmp+nKcYH
  12. BbOOyzIuZpmwKP3UmGYo2P9oorBDPdA3fp8raeV3ia/9CasdWwZ717v6NYWg2cT4
  13. tHXtMM52i8JRHrQseCq22FUj0rU/jpxPa5ZtykAZToigM8XbtDiUAsE53MUZX7y4
  14. 5dqtRcaMwWWwCEaO8SuMvaXXch8ASDAS3SU2L4z8MZNoshcRM9wauO5fFPFsGqyv
  15. OU+fay6DC8kBIorZYJmt7ce8x+NQZM2WQIs7aLbcTMvDv/86D9S6G6qGycQv0gxc
  16. qVqPdasud83&kjasd83kjasWejasHASJ1u4zvel2Q/Jpm3KYjwakri4jhFkjQ9zS
  17. muuhM5DkYu9mAd2WCwYntw==
  18. Private-MAC: b2385da6a3dbcd49fa90ea9c336fac575952645e

Now, load your PuTTY client and at left for category click on ‘Connection’ ‘“ ‘SSH’ ‘“ ‘Auth’. There under the section ‘Authentication parameters’ locate ‘Private key file for authentication‘, and browse for your new key.
The next will be to connect to your server.

Tags

Filed Under: SSH

Anthony Gee About the Author: Anthony G. is an IT specialist with more than 9 years of solid working experience in the Web Hosting industry. Currently works as server support administrator, involved in consultative discussions about Web Hosting and server administration. One of the first writers in the Onlinehowto.net website, now writing for Free Tutorials community - he is publishing tutorials and articles for the wide public, as well as specific technical solutions.

Comments (3)

  1. Anthony Gee Rashid says:

    I was shaking my head for a while, why I cannot connect with putty to my linux server, and this tutorial helped me.
    Thanks!

  2. RubenBCR says:

    Something that was driving me crazy: if you are getting “not a private key” errors when trying to import the text file you created, make sure you don’t have any extra spaces or lines in your document, it has to start with

    ‘”’“BEGIN RSA PRIVATE KEY’”’“

    And finish with

    ‘”’“END RSA PRIVATE KEY’”’“

    Be very strict about this and try again, worked for me (after several self inflicted corporal punishment attempts).

Leave a Reply