Page 1 of 1

Can't connect to Mikrotik via libssh2

Posted: Thu Oct 07, 2010 2:35 pm
by timmartin
I was trying to write a PHP script to manage a RouterOS box, and I hit a problem that PHP SSH can't seem to connect to RouterOS, though it can connect to other SSH servers.

I've narrowed the problem down as far as discovering it's nothing to do with PHP - libssh2 can't connect to RouterOS, though it can connect to a linux box running openssh-server.

I've written a small test using libssh2 that demonstrates this:

http://gist.github.com/614962

If you give it the IP of a linux server it works, if you give it a Mikrotik (in my case an RB750G running 3.31) it gives

"Unable to exchange encryption keys"

Does anyone have any suggestions what might be causing this? Is libssh2 missing support for the necessary protocol?

Re: Can't connect to Mikrotik via libssh2

Posted: Thu Oct 07, 2010 3:29 pm
by cieplik206
Maybe its related but Android App "Connect Bot" cannot connect using SSH to Mikrotik Neither.

Re: Can't connect to Mikrotik via libssh2

Posted: Thu Oct 07, 2010 4:10 pm
by timmartin
In case it's any use to anyone, I've managed to capture a libssh debug log of the process failing:

http://gist.github.com/615074

Re: Can't connect to Mikrotik via libssh2

Posted: Thu Oct 07, 2010 4:18 pm
by abeggled
There are other threads regarding this issue. Search for php & ssh ...

Re: Can't connect to Mikrotik via libssh2

Posted: Thu Oct 07, 2010 4:40 pm
by timmartin
I couldn't find anything dealing with this issue specifically, although in this thread:

http://forum.mikrotik.com/viewtopic.php?f=9&t=1957

some working code is given as an example. The solution is to add:
$methods = array(
  'kex' => 'diffie-hellman-group1-sha1'
);

$connection = ssh2_connect($server, 22, $methods);
I infer that the problem is that libssh2 wants to do a Diffie-Hellman group exchange, but RouterOS isn't expecting to see that. This still seems like a clear bug in either libssh2 or RouterOS - if it's the former then perhaps someone can confirm to me and I'll report it to the libssh2 people.

Either way, I have a workaround now.

Re: Can't connect to Mikrotik via libssh2

Posted: Fri Oct 08, 2010 1:00 pm
by Rhapsody01
Its a problem that concern RouterOS V4 and below.
In V5 a new implementation of SSH has been done and should solve this 'Bug'.

Re: Can't connect to Mikrotik via libssh2

Posted: Tue Jan 11, 2011 6:47 pm
by creagel
$methods = array(
'kex' => 'diffie-hellman-group1-sha1'
);

$connection = ssh2_connect($server, 22, $methods);
Is there a solution of this problem for python and libssh2 (pylibssh2 - http://pypi.python.org/pypi/pylibssh2/) ?