我想创建一个 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://manpages.debian.org/stable/putty-tools/puttygen.1.en.html
在 Windows 上,PuTTYgen 只是一个 GUI 应用程序。不过,您可以使用 WinSCP,它具有 PuTTYgen 兼容的命令行界面:
winscp.com /keygen openssl-key -o mykey.ppk