PHP / Bash: Creating PPK out of OpenSSH Key with passphrase

巧了我就是萌 提交于 2019-12-12 10:26:30

问题


I would like to create a php script that creates keys for ssh-authentication. I've started with a

exec("ssh-keygen -b 1024 -t dsa -N *pwd* -f *path-to-file* -q");

to create the private and public-key-pair. No problem till here ;)

Now I've to convert the OpenSSL-Key to the ppk-format of PuTTY (in the cmd, not in the GUI). If anyone have an Idea on how to manage that, please let me know.

Thanks


回答1:


If you were working with RSA keys you could do this (requires phpseclib):

<?php
include('Crypt/RSA.php');

$rsa = new Crypt_RSA();
$rsa->setPassword('password');
$rsa->loadKey('...');

//$rsa->setPassword(); // clear the password if there was one
echo $rsa->getPrivateKey(CRYPT_RSA_PRIVATE_FORMAT_PUTTY);
?>



回答2:


You have not specified, what OS you run at. On *nix, you can use PuTTYgen (from PuTTY):

puttygen openssl-key -o mykey.ppk

For details see: https://linux.die.net/man/1/puttygen

On Windows, PuTTYgen is a GUI application only. Though, you can use WinSCP, it has PuTTYgen-compatible command-line interface:

winscp.com /keygen openssl-key -o mykey.ppk


来源:https://stackoverflow.com/questions/16132200/php-bash-creating-ppk-out-of-openssh-key-with-passphrase

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