我使用的是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');
}