php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57427 ssh2_tunnel(): Unable to request a channel from remote host
Submitted: 2006-12-14 11:06 UTC Modified: 2012-06-22 15:06 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: metal3d at gmail dot com Assigned:
Status: Not a bug Package: ssh2 (PECL)
PHP Version: 5.1.6 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
42 + 9 = ?
Subscribe to this entry?

 
 [2006-12-14 11:06 UTC] metal3d at gmail dot com
Description:
------------
Creating tunnel by command line ok:
ssh -N -f root@172.17.6.126 -L55959:localhost:80

But with php (same user, command line call):
PHP Warning:  ssh2_tunnel(): Unable to request a channel from remote host in /home/patricef/tmp/tunnel.php on line 4


What is the problem ?
See the code given to reproduce the bug

Reproduce code:
---------------
<?php
$connection = ssh2_connect('172.17.6.126', 22,array('hostkey'=>'ssh-rsa'));
ssh2_auth_pubkey_file($connection, 'root', '/home/patricef/.ssh/id_rsa.pub', '/home/patricef/.ssh/id_rsa');
$tunnel = ssh2_tunnel($connection, '172.28.1.4:80', 55655);
?>


Expected result:
----------------
I want to have my tunnel opened...

Actual result:
--------------
No backtrace
PHP Warning:  ssh2_tunnel(): Unable to request a channel from remote host in /home/patricef/tmp/tunnel.php on line 4


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-28 09:02 UTC] s91066 at yahoo dot gr
OK, I have the same problem. What bothers me is the fact that no one seems to either answer the original question or to update the documentation. Actually, a good example is what we need. I have the same problem with ssh2_tunnel.

$con=ssh2_connect($remote_host, 22);
if (ssh2_auth_password($connection, $SSH_USER, $PASS))
{
   if ($tunnel = ssh2_tunnel($con, "$remote_host:$remote_port", $local_port))
      echo "Tunnel OK";
   else
      echo "Tunnel creation failed.";
}

Guess what. No tunnel is created! The message was:
PHP Warning:  ssh2_tunnel(): Unable to request a channel from remote host

So, either I have not understood how to create a tunnel (since the manual is not very helpful on the issue),
or the ssh2_tunnel does not work...
Some notes:
The ssh2_tunnel function uses 3 parameters. I thought that we need one more parameter!
Now, function uses a host/port combination (which host is not clear). But either the local or the remote servers port is not given in the function! I suppose that this is the reason that my connection is failed. 

We need support here...
 [2008-05-08 19:50 UTC] volkirik at yahoo dot com dot tr
resource ssh2_tunnel  ( resource $session  , string $host  , int $port  )

ssh2_tunnel accepts 3 parameters and all parameters are required:

session (resource id) => An SSH connection link identifier, obtained from a call to ssh2_connect().

host (string) => Third party host to connect to using the SSH host as a proxy.

port (integer) => Port on third party host to connect to.

Unfortunately you can not specify source host and source(local) port with ssh2_tunnel function.


using following code works as expected:

$remote_host = '172.17.6.126';
$remote_port = 22;

$tunnel = ssh2_tunnel($con, $remote_host, $remote_port);
 [2008-05-08 21:06 UTC] volkirik at yahoo dot com dot tr
You need to patch ssh2_fopen_wrappers.c file for ssh2_tunnel function
if you want to specify source host and source port parameters.:

open up ssh2_fopen_wrappers.c file.

1) CHANGE following line (LINE 1175 on ssh2 v0.10):

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &zsession, &host, &host_len, &port) == FAILURE) {

TO

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl|sl", &zsession, &host, &host_len, &port, &shost, &shost_len, &sport) == FAILURE) {

2) CHANGE following line (LINE 1181 on ssh2 v0.10):

	stream = php_ssh2_direct_tcpip(session, Z_LVAL_P(zsession), host, port TSRMLS_CC);

TO

	stream = php_ssh2_direct_tcpip(session, Z_LVAL_P(zsession), host, port, shost, sport TSRMLS_CC);

3) AFTER following lines (LINE 1172 on ssh2 v0.10):

	int host_len;
	long port;

ADD

	char *shost = "127.0.0.1";
	int shost_len;
	long sport = 22;

 
4) CHANGE following line (LINE 1065 on ssh2 v0.10):

static php_stream *php_ssh2_direct_tcpip(LIBSSH2_SESSION *session, int resource_id, char *host, int port TSRMLS_DC)

TO

static php_stream *php_ssh2_direct_tcpip(LIBSSH2_SESSION *session, int resource_id, char *host, int port, char *shost, int sport TSRMLS_DC)


5) CHANGE following line (LINE 1071 on ssh2 v0.10):

	channel = libssh2_channel_direct_tcpip(session, host, port);

TO

	channel = libssh2_channel_direct_tcpip_ex(session, host, port, shost, sport);

6) CHANGE following line (LINE 1138 on ssh2 v0.10):

	stream = php_ssh2_direct_tcpip(session, resource_id, host, port TSRMLS_CC);

TO

	stream = php_ssh2_direct_tcpip(session, resource_id, host, port, shost, sport TSRMLS_CC);

7) AFTER following lines (LINE 1101 on ssh2 v0.10):

	int port = 0;
	int resource_id = 0;

ADD

	char *shost = "127.0.0.1";
	long sport = 22;


Follow steps one-by-one and compile again. Tested on Fedora core 4 with libssh2 v0.18 and pecl/ssh2 v0.10


IMPORTANT NOTE: For older versions of ssh2 extension LINE numbers may be different. Do this only if you know what you do!


----
Volkan K.
 [2009-02-17 06:44 UTC] gevorg dot ha at gmail dot com
Hi,

Is there any way to use $tunnel resource after ssh2_tunnel is executed.Could you please give me some short sample on this. Or if it is possible can you help me to get local port number after tunnel is opened?

Thanks a lot,
Gevorg
 [2012-06-22 15:06 UTC] langemeijer@php.net
-Status: Open +Status: Not a bug
 [2012-06-22 15:06 UTC] langemeijer@php.net
ssh2_tunnel() does *NOT* open a listening socket on the local host. Instead it 
opens a tcp connection through the SSH server to the host specified.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC