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?


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

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

Or build your own tool from PuTTY code. It's open-source. It should be pretty easy.

Use the import_ssh2 to load the .pem:

struct 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:

int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
          char *passphrase)
  • 1
    I was only trying to construct a convenience script. But this is the most useful information I can probably get. – Der Hochstapler May 9 '15 at 9:18
  • 1
    WinSCP 5.8 beta with command-line support for converting private key has been released. – Martin Prikryl Jan 6 '16 at 14:09
  • Awesome! I'll give it a try the next time the issue comes up :) – Der Hochstapler Jan 6 '16 at 14:55
  • If it hangs waiting for a keypress, you are probably using winscp.exe instead of winscp.com. WinSCP has a really odd way to specify non-interactive mode. – Robert Važan Apr 4 '17 at 23:48
  • @RobertVažan It's not about non-interactivity. If you want to script something, you should use a console application, not GUI application. Read about WinSCP executables. – Martin Prikryl Apr 5 '17 at 7:39

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



  • The question is about "Windows command line". – Martin Prikryl Dec 19 '17 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. – sancho.s Dec 19 '17 at 15:51

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

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 '17 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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