我使用的是SSH-DSS
密钥,端口是2222
。我可以使用公钥/私钥(peagent)和用户名从我的机器通过winscp进行连接。 (私钥没有密码)SFTP公钥失败,没有错误
但是,当我尝试与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');
}