Php ssh - Error starting up SSH connection(-1)

2.1k views Asked by At

I want to connect to another server by ssh using PHP but i get error as below .i looked for it very much but couldn't find any suitable solution for me.

Warning: ssh2_connect(): Error starting up SSH connection(-1): Failed sending banner in ... Warning: ssh2_connect(): Unable to connect to ...

this is my php code :

$connection = ssh2_connect($details[0]['address'], $details[0]['port']);
ssh2_auth_password($connection, $details[0]['username'], $details[0]['password']);
1

There are 1 answers

1
conducode On

Trying to diagnose issues with libssh2 is nigh impossible. My recommendation: use phpseclib, a pure PHP SSH implementation, and assuming that doesn't resolve the issue you can get logs that'll assist in the diagnosis. eg.

<?php
include('Net/SSH2.php');

define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);

$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}

echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');

echo $ssh->getLog();
?>