PHP / Bash:创建PPK的OpenSSH密钥与passphrase


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

我想创建一个php脚本,为ssh认证创建密钥。我从

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

创建私钥对和公钥对。到这里都没问题;)

现在我必须将OpenSSL-Key转换为PuTTY的ppk格式(在cmd中,而不是在GUI中)。如果有人对如何管理有任何想法,请告诉我。

谢谢

如果您正在使用RSA密钥,您可以这样做(需要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);
?>

您没有指定您运行的操作系统。在*nix上,您可以使用PuTTYgen(从PuTTY):

puttygen openssl-key -o mykey.ppk

详细信息参见:https://linux.die.net/man/1/puttygen

在Windows上,PuTTYgen只是一个GUI应用程序。尽管您可以使用WinSCP,但它具有与puttygen兼容的命令行界面:

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