无法使用 PHP 函数 ssh2_tunnel 创建 SSH 隧道
Posted
技术标签:
【中文标题】无法使用 PHP 函数 ssh2_tunnel 创建 SSH 隧道【英文标题】:Can not create SSH tunnel with PHP function ssh2_tunnel 【发布时间】:2016-11-10 14:12:49 【问题描述】:我正在使用带有 ssh2 扩展的 php 5.6 来创建到远程主机的 SSH 隧道,这是我的代码:
$connection = ssh2_connect($host[0], 22);
if (ssh2_auth_password($connection, $host[1], $host[2]))
if ($tunnel = ssh2_tunnel($connection, '127.0.0.1', 1080))
//curl commands
我可以使用 ssh2_exec
执行一些 Linux 命令,但无法使用 ssh2_tunnel
创建 SSH 隧道,这里是错误日志:
PHP 警告:ssh2_tunnel():无法从远程主机请求通道
谁能给我一些提示?
【问题讨论】:
【参考方案1】:您要连接的 SSH 服务器未启用 TCP 转发(即AllowTcpForwarding no
)。您需要请求服务器管理员启用它。
【讨论】:
感谢@duskwuff,我已经在自己的服务器上进行了测试,默认设置了AllowTcpForwarding yes
。我已通过此服务器成功使用 Putty 进行隧道传输,但无法找到使用 PHP 的方法以上是关于无法使用 PHP 函数 ssh2_tunnel 创建 SSH 隧道的主要内容,如果未能解决你的问题,请参考以下文章