How do you convert an SSH private key to a .ppk on the Windows 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

(I'm the author of WinSCP)


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 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);

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

https://devops.profitbricks.com/tutorials/use-ssh-keys-with-putty-on-windows/

https://kb.site5.com/shell-access-ssh/how-to-convert-ssh-keys-to-ppk-format/


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.