I have generated a key pair with ssh-keygen. I now want to use the same key pair with PuTTY-based applications.

Because I'm working in a CLI environment, I want to convert the key to the .ppk format from within this environment.

Apparently, you can use puttygen openssh_private_key -o output_filename.ppk on UNIX-like environments. But the Windows version of puttygen will just load the key and prompt you to use the GUI to export the key.

Batch mode for Windows PuTTYgen suggests that this simply is not currently possible, at least with puttygen. I'd gladly accept and option that uses other means though.

How can I convert the key from the command line?

3 Answers 3


WinSCP supports command-line conversion of private keys from the OpenSSH (or ssh.com) format to the PuTTY .ppk format.

Use the /keygen switch:

winscp.com /keygen mykey.pem /output=mykey.ppk

(I'm the author of WinSCP)

Or, you can compile/run the Unix command-line puttygen using Cygwin.

Or install them using WSL:

sudo apt install putty-tools # for ubuntu

Then, in both cases:

puttygen mykey.pem -O private -o mykey.ppk

Or build your own tool from PuTTY code. It's open-source. It is rather easy (that's basically what WinSCP does).

Use the import_ssh2 to load the .pem:

ssh2_userkey *import_ssh2(const Filename *filename, int type,
                          char *passphrase, const char **errmsg_p);

Use the ppk_save_f to save it as the .ppk:

bool ppk_save_f(const Filename *filename, ssh2_userkey *key,
                const char *passphrase, const ppk_save_parameters *params)
  • 1
    Thank you! That actually works betty than using puttygen from the command-line because in Windows, puttygen.exe does not support all of the same commands that it does in Linux, so you end up with this error without using WinSCP to do it.
    – asheroto
    Dec 3, 2023 at 7:46

NOTE: The OP requires Command line. This answer uses a graphical application... Will leave the answer here just in case it is useful.

There is a possibly simpler solution.

1) Download (if you do not already have it) the PuTTY Key Generator (PuTTYgen) application by going here or here.

2) Open PuTTYgen

3) Click Conversions, then click import key

4) Locate your key file, then click open.

You can now save your key as a PPK file by clicking the Save private key button

You can also save a public version of your key by clicking the Save public key button



  • 3
    The question is about "Windows command line". Dec 19, 2017 at 12:48
  • @MartinPrikryl - You are correct, I will make a note on it. I could as well remove it, but I have seen very often similar cases where readers judged answers useful anyway. And this is the main goal of SO. Dec 19, 2017 at 15:51
  • 1
    This anwer may not be as useful as just referring to the official documentation for this program at the.earth.li/~sgtatham/putty/latest/htmldoc/… although admittedly this answer is shorter. But at the time of this writing the first link is to putty.org which is not positively referred to by the.earth.li/~sgtatham/putty/latest/htmldoc/… so I feel I should downvote this as more likely to cause more harm than help (unless I later notice this answer is fixed in a change newer than 2022-July-10 about 7:45am PST)
    – TOOGAM
    Jul 10, 2022 at 14:44

If you're running on linux or generating your key there (or maybe you can?) then you can use

puttygen -t rsa -C "my home key" -o mykey.ppk

If you don't have puttygen already, then sudo apt install putty-tools or the appropriate command on your system to install it.

Otherwise if you're on windows I can't see how you can actually do it, other than generating the key on another machine.

  • 1
    This is what I use so far but one annoyance is that in Windows at least, it leaves the puttygen window open, havent found a way to automatically close it
    – Purefan
    Jan 30, 2017 at 8:59
  • 2
    Best answer. No manual downloads, just sudo apt install putty-tools and then the above puttygen command, and you're done. You can put the path to the original key instead of "my home key". Sep 4, 2019 at 21:08
  • The best answer? OP is asking for conversion not creating an rsa key in ppk format. Most people upvoting because they found this helpful to them in another case but clearly this answer did not follow OP request.
    – Kalib Zen
    Apr 19, 2021 at 8:48
  • @KalibZen The author only states that he is working in a client environment on windows. The WSL2 can do the job with this answer. Sep 16, 2022 at 6:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .