我正在使用SSH-DSS
密钥,端口是2222
. 我可以使用公钥/私钥(peagent)和用户名从我的机器通过winscp进行连接。(私钥没有密码)
但是当我尝试使用 PHP 脚本时它不起作用。没有错误信息。ssh2_auth_pubkey_file()
返回blank
/ false
。所以脚本以
公钥认证失败
有什么方法可以调试错误吗?
公钥/私钥是使用 puttygen 生成的。
这是我正在使用的代码片段:
$methods = array('hostkey' => 'ssh-dss');
$connection = ssh2_connect('sftp.hostname.com', 2222, $methods);
if (!$connection) die('Connection failed');
$publicKeyPath = "./pubKey-OpenSSH";
$privateKeyPath = "./priKey.ppk";
echo file_get_contents($publicKeyPath);
echo "<hr />";
echo file_get_contents($privateKeyPath);
echo "<hr />";
if(ssh2_auth_pubkey_file($connection, 'USERNAME', $publicKeyPath, $privateKeyPath, ""))
{
echo "<br /><br /><b>Public Key Authentication Successful</b>\n";
}
else
{
print_r($connection);
die('<br /><br />Public Key Authentication Failed');
}