2016-09-20 101 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密鑰