Php 具有公钥的SFTP失败且无错误

Php 具有公钥的SFTP失败且无错误,php,sftp,ssh2-sftp,Php,Sftp,Ssh2 Sftp,我正在使用SSH-DSS键,端口是2222。我可以使用公钥/私钥(peagent)和用户名通过winscp从我的机器进行连接。(私钥没有密码短语) 但是当我尝试使用PHP脚本时,它不起作用。没有错误消息ssh2\u auth\u pubkey\u file()返回blank/false。所以脚本以 公钥身份验证失败 有什么方法可以调试错误吗 使用puttygen生成公钥/私钥 以下是我正在使用的代码片段: $methods = array('hostkey' => 'ssh-dss

我正在使用
SSH-DSS
键,端口是
2222
。我可以使用公钥/私钥(peagent)和用户名通过winscp从我的机器进行连接。(私钥没有密码短语)

但是当我尝试使用PHP脚本时,它不起作用。没有错误消息
ssh2\u auth\u pubkey\u 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');
    }
$methods=array('hostkey'=>'ssh-dss');
$connection=ssh2_connect('sftp.hostname.com',2222,$methods);
如果(!$connection)死亡('connection failed');
$publicKeyPath=“/pubKey OpenSSH”;
$privateKeyPath=“./priKey.ppk”;
回显文件获取内容($publicKeyPath);
回声“
”; 回显文件获取内容($privateKeyPath); 回声“
”; if(ssh2_auth_pubkey_文件($connection,'USERNAME',$publicKeyPath,$privateKeyPath,“)) { echo“

公钥身份验证成功\n”; } 其他的 { 打印(连接); die(“

公钥身份验证失败”); }
如果您具有服务器的root访问权限,则可以停止ssh守护进程并从

ssdh -ddd

用于调试,并注意错误。

私钥是ppk。需要是pem或der才能使用
ssh2\u auth\u pubkey\u文件
。通过转到Conversions->Export OpenSSH key,可以使用puttygen将密钥转换为适当的格式