laffoyb
laffoyb

Reputation: 1580

Convert .pem key file to .ppk in Windows automatically/script/command line

I'm using Vagrant to create VMs on a Windows host, to which I would like to connect with PuTTY. Vagrant creates an RSA private key in the .pem format. PuTTY needs a key in the .ppk format to create a connection.

I would like to convert the .pem to .ppk automatically when creating the vagrant VM.

The question of how to convert .pem to .ppk has been asked and answered lots of times, but on Windows all those answers involve clicking through the puttygen GUI. It seems that on Linux, puttygen can be operated entirely from the command line, but on Windows the GUI must be used.

Having to click through a GUI is a slow point in my workflow when creating new VMs that I would like to avoid.

Is there any command-line/scriptable/programmatic way of converting .pem files to .ppk format on Windows?

Upvotes: 3

Views: 12546

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202088

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 Unix command-line puttygen using Cygwin.


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

Use import_ssh2 to load the .pem:

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

Use ppk_save_f to save it as .ppk:

bool ppk_save_f(const Filename *filename, ssh2_userkey *key,
                const char *passphrase, const ppk_save_parameters *params);

Upvotes: 15

Related Questions