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

ぃ、小莉子 提交于 2020-02-28 08:42:22

问题


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?


回答1:


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

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



回答2:


I've written a utility that will do this for you because it drove me nuts too. It will monitor a directory and convert them automatically as they arrive. Will also let you quick launch putty sessions.

Grab a copy from here



来源:https://stackoverflow.com/questions/29646720/convert-pem-key-file-to-ppk-in-windows-automatically-script-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!