2016-09-20 104 views
2

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

回答

0

如果你有服务器的root访问权限,可以停止ssh守护进程,并与

ssdh -ddd 

为了调试开始,注意那里的错误。

0

私钥是一个ppk。需要成为可以与ssh2_auth_pubkey_file一起工作的人。您可以使用puttygen将密钥转换为适当的格式,方法是转到 - >导出OpenSSH密钥