2

我正在使用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');
    }
4

2 回答 2

0

如果您对服务器具有 root 访问权限,则可以停止 ssh 守护程序并以

ssdh -ddd

用于调试,并注意那里的错误。

于 2016-09-20T15:14:59.663 回答
0

私钥是一个 ppk。需要成为 pem 才能使用ssh2_auth_pubkey_file。您可以使用 puttygen 将密钥转换为适当的格式,方法是转到 Conversions -> Export OpenSSH key

于 2016-09-21T15:49:23.730 回答