|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-06-05 18:57 UTC] fishgills at fishgills dot net
Description:
------------
I'm getting this error when using the SSH2 0.12 from its beta PECL channel
It's a very simple test script. I have all the required packages installed.
Reproduce code:
---------------
<?php
$connect = ssh2_connect('d50-1.s50', 22);
if (!$connection) die('Connection failed');
?>
Expected result:
----------------
To get a connection to the specified host.
Actual result:
--------------
PHP Warning: ssh2_connect(): Error starting up SSH connection(-5): Unable to exchange encryption keys in /tmp/test.php on line 2
PHP Warning: ssh2_connect(): Unable to connect to d50-1.s50 in /tmp/test.php on line 2
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 06:00:02 2025 UTC |
I'm running libssh2 at verison 0.14 and ssh2 is at 0.10 as well. Fedora 5 php code: $connection = ssh2_connect('192.168.13.1', 22); if (!$connection) die('Connection failed'); result: PHP Warning: ssh2_connect(): Error starting up SSH connection(-5): Unable to exchange encryption keys in /root/to-nas/ssh.php on line 3 PHP Warning: ssh2_connect(): Unable to connect to 192.168.13.1 in /root/to-nas/ssh.php on line 3 Connection failedHere is a class we wrote to solve this particular problem: <?php /* Author: Benjamin Menking <ben@infotechsc.com> Additional coding by David Johnson <davemann619@gmail.com> This code is public domain. The author makes no warranty or guarantee of fitness or accuracy. The author would love to recieve changes and modifications to this code, if you are inclined to share. */ class SSH2_conn { const NO_PTY = false; private static $methods = array( 'kex' => 'diffie-hellman-group1-sha1', 'hostkey' => 'ssh-dss', 'client_to_server' => array( 'crypt' => '3des-cbc', 'mac' => 'hmac-md5', 'comp' => 'none'), 'server_to_client' => array( 'crypt' => '3des-cbc', 'mac' => 'hmac-md5', 'comp' => 'none')); private $ip, $name, $pass; function __construct($ip, $name, $pass) { $this->ip = $ip; $this->name = $name; $this->pass = $pass; } function exec($cmd) { $conn = $this->_connect(); $stream = ssh2_exec($conn, $cmd, self::NO_PTY); if( $stream === false ) die('no stream available'); return $stream; } function exec_print($cmd) { $conn = $this->_connect(); $stream = ssh2_exec($conn, $cmd, self::NO_PTY); if( $stream === false ) die('no stream available'); while( !feof($stream) ) { $line = fgets($stream); echo $line; } fclose($stream); } function _connect() { $conn = ssh2_connect($this->ip, 22, self::$methods); if( $conn === false ) die("Could not connect!\n"); // use this line for username/password authentication $test = ssh2_auth_password($conn, $this->name, $this->pass); // use this code snippet for public/private key authentication (much nicer IMHO) //$test = ssh2_auth_pubkey_file($conn, 'webuser', // '/root/.ssh/id_dsa.pub', // '/root/.ssh/id_dsa', ''); if( $test === false ) die("Failed!\n"); return $conn; } } class Router { private $ip, $conn; function __construct($ip, $name, $pass) { $this->ip = $ip; $this->conn = new SSH2_conn($ip, $name, $pass); } function add_extern_user($user, $ip, $port, $rip, $comment) { $this->conn->exec_print("/ip firewall nat add chain=dstnat action=dst-nat to-addresses=$ip to-ports=$port dst-address=$rip comment=\"$comment\" protocol=tcp"); } function add_pptp_user($name, $rip, $pass) { $ip = $this->ip; $this->conn->exec_print("/ppp secret add name=$name service=pptp local-address=$ip remote-address=$rip password=$pass"); } function add_static_user($user, $ip) { // not needed } function verify_extern_account($name, $ip, $port, $rip, $comment) { $stream = $this->conn->exec('/ip firewall nat print'); $str = ''; while( !feof($stream) ) { $line = fgets($stream); $str .= $line; } $comment = preg_quote($comment); return (preg_match("/$comment\s+chain=dstnat\s+action=dst-nat\s+to-addresses=$ip\s+to-ports=$port\s+dst-address=$rip\s+protocol=tcp/m", $str) > 0); } function verify_pptp_account($name, $rip, $pass, $comment) { $stream = $this->conn->exec('/ppp secret print terse'); $str = ''; while( !feof($stream) ) { $line = fgets($stream); $str .= $line; } fclose($stream); $comment = preg_quote($comment); return (preg_match("/name=$name/m", $str) > 0); } function verify_static_account($name, $ip) { return true; } } // test unit code. comment out to use class $router = new Router('192.168.1.1', 'admin', ''); $router->add_pptp_user('foo', '192.168.1.250', 'bar'); $router->print_status(); ?>