I'm using SSH-DSS
key, port is 2222
. I'm able to connect through winscp from my machine using public/private keys (peagent) and username. (Private key is without passphrase)
But when I try the same with PHP script it doesn't work. No error message. ssh2_auth_pubkey_file()
returns blank
/false
. So script ends up with
Public Key Authentication Failed
Is there any method to debug the error?
Public/Private keys are generated with puttygen.
Here is the code snippet I'm using:
$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');
}