SSH 通过隧道访问远程客户端

Posted

技术标签:

【中文标题】SSH 通过隧道访问远程客户端【英文标题】:SSH access a remote client through a tunnel 【发布时间】:2014-02-13 21:03:05 【问题描述】:

我是一个与网络相关的所有东西的新手,我想通过另一台服务器(隧道)访问远程客户端, 比如说一个远程客户端 11.11.111.111 用户名 user2 和 password2 ,一个隧道通过 11.11.10.01 用户名 user1 和 password1

我可以 ping 通地址隧道地址。 但是当我尝试使用 cygwin 访问远程客户端时:

ssh -vv -o 'ProxyCommand ssh -vv user1@11.11.10.01 nc %h %p' user2@11.11.111.111

我得到这个错误:

OpenSSH_6.4, OpenSSL 1.0.1f 6 Jan 2014
debug2: ssh_connect: needpriv 0
debug1: Executing proxy command: exec ssh -vv user1@11.11.10.01 nc 11.11.111.111 22
debug1: permanently_drop_suid: 146765
debug1: identity file /home/user1/.ssh/id_rsa type -1
debug1: identity file /home/user1/.ssh/id_rsa-cert type -1
debug1: identity file /home/user1/.ssh/id_dsa type -1
debug1: identity file /home/user1/.ssh/id_dsa-cert type -1
debug1: identity file /home/user1/.ssh/id_ecdsa type -1
debug1: identity file /home/user1/.ssh/id_ecdsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.4
OpenSSH_6.4, OpenSSL 1.0.1f 6 Jan 2014
debug2: ssh_connect: needpriv 0
debug1: Connecting to 11.11.10.01 [11.11.10.01] port 22.
debug1: connect to address 11.11.10.01 port 22: Connection timed out
ssh: connect to host 11.11.10.01 port 22: Connection timed out
ssh_exchange_identification: Connection closed by remote host

我的命令是否正确,关于可能原因的任何想法?

有什么方法可以排除故障(最好在我的机器上而不是在服务器和远程客户端上)?

【问题讨论】:

你在11.11.10.01安装了nc吗? 我无法访问并验证,有没有办法远程知道? 你能联系ssh user1@11.11.10.01吗? 即使只有我得到连接超时,这是否意味着 11.11.10.01 没有 ssh 运行? 极有可能在您的日志中没有组装连接。 debug1: Connecting to 11.11.10.01 [11.11.10.01] port 22.debug1: connect to address 11.11.10.01 port 22: Connection timed out 【参考方案1】:

我相信这只是部分答案,但请尝试使用 ssh 连接到 11.11.10.01:

ssh user1@11.11.10.01 -L20022:11.11.111.111:22

然后在另一个窗口中通过以下方式连接:

ssh user2@127.0.0.1 -p20022

这样你会在第一个终端窗口中得到你的错误。

【讨论】:

以上是关于SSH 通过隧道访问远程客户端的主要内容,如果未能解决你的问题,请参考以下文章

在 Java 中通过 SSH 隧道运行远程命令

apt-get 通过隧道代理安装,但 ssh 仅来自客户端

配置SSH隧道访问Ubuntu服务器上的MongoDB

使用 Java 通过 SSH 隧道传输文件

jmx/jstatd 通过 ssh 隧道访问远程机器

通过 ssh 隧道访问远程数据库(Python 3)