2

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');
    }
mtb
  • 1,350
  • 16
  • 32
Swapnil
  • 31
  • 2

2 Answers2

0

If you have root access to the server, you can stop the ssh daemon and start with

ssdh -ddd

For debugging, and watch for errors there.

0

Private Key is a ppk. Needs to be a pem or der to work with ssh2_auth_pubkey_file. You can use puttygen to convert key to appropriate format by going to Conversions -> Export OpenSSH key

neubert
  • 15,947
  • 24
  • 120
  • 212