How do you convert an SSH private key to a .ppk on the Windows command line?


Solution 1

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

Use the /keygen switch: /keygen mykey.pem /output=mykey.ppk

(I'm the author of WinSCP)

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

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 ssh2_save_userkey to save it as the .ppk:

bool ssh2_save_userkey(
    const Filename *filename, ssh2_userkey *key, char *passphrase);

Solution 2

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

Solution 3

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.


Related videos on Youtube

Oliver Salzburg
Author by

Oliver Salzburg

Updated on September 18, 2022


  • Oliver Salzburg
    Oliver Salzburg almost 2 years

    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?

  • Purefan
    Purefan over 7 years
    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
  • Martin Prikryl
    Martin Prikryl over 6 years
    The question is about "Windows command line".
  • sancho.s ReinstateMonicaCellio
    sancho.s ReinstateMonicaCellio over 6 years
    @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.
  • Andrew Koster
    Andrew Koster almost 5 years
    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".
  • Kalib Zen
    Kalib Zen about 3 years
    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.
  • Admin
    Admin almost 2 years
    This anwer may not be as useful as just referring to the official documentation for this program at… although admittedly this answer is shorter. But at the time of this writing the first link is to which is not positively referred to by… 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)