Community discussions

MikroTik App
 
timmartin
just joined
Topic Author
Posts: 12
Joined: Wed Sep 01, 2010 12:01 pm

Can't connect to Mikrotik via libssh2

Thu Oct 07, 2010 2:35 pm

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?
 
cieplik206
Trainer
Trainer
Posts: 290
Joined: Sun Jul 01, 2007 12:25 am
Contact:

Re: Can't connect to Mikrotik via libssh2

Thu Oct 07, 2010 3:29 pm

Maybe its related but Android App "Connect Bot" cannot connect using SSH to Mikrotik Neither.
 
timmartin
just joined
Topic Author
Posts: 12
Joined: Wed Sep 01, 2010 12:01 pm

Re: Can't connect to Mikrotik via libssh2

Thu Oct 07, 2010 4:10 pm

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
 
abeggled
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Mon Aug 16, 2010 4:00 pm
Location: Zollikofen, Switzerland

Re: Can't connect to Mikrotik via libssh2

Thu Oct 07, 2010 4:18 pm

There are other threads regarding this issue. Search for php & ssh ...
 
timmartin
just joined
Topic Author
Posts: 12
Joined: Wed Sep 01, 2010 12:01 pm

Re: Can't connect to Mikrotik via libssh2

Thu Oct 07, 2010 4:40 pm

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.
 
Rhapsody01
just joined
Posts: 13
Joined: Thu Mar 05, 2009 6:29 pm
Location: France

Re: Can't connect to Mikrotik via libssh2

Fri Oct 08, 2010 1:00 pm

Its a problem that concern RouterOS V4 and below.
In V5 a new implementation of SSH has been done and should solve this 'Bug'.
 
creagel
just joined
Posts: 1
Joined: Tue Jan 11, 2011 6:44 pm

Re: Can't connect to Mikrotik via libssh2

Tue Jan 11, 2011 6:47 pm

$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/) ?