如何 ssh 登录另一局域网的主机

2015-10-13 11:05:30 +08:00
 FindHao

先不要说设置路由器转发功能的那个,因为路由器的密码不知道。有没有别的方法。

另外,有方法可以不进行物理接触破解路由器的管理密码吗?

6161 次点击
所在节点    SSH
5 条回复
FindHao
2015-10-13 11:07:41 +08:00
哦。不用了。。。找到了方法。


问题描述:
机器状况
机器号 IP 用户名 备注
A 192.168.0.A usr_a 目标服务器,在局域网中,可以访问 A
B B.B.B.B usr_b 代理服务器,在外网中,无法访问 A
C - - 可以直接访问 B ,无法直接访问 A
目标
从 C 机器使用 SSH 访问 A

解决方案
在 A 机器上做到 B 机器的反向代理;在 B 机器上做正向代理本地端口转发

环境需求
每台机器上都需要 SSH 客户端
A 、 B 两台机器上需要 SSH 服务器端。通常是 openssh-server 。

在 Ubuntu 上安装过程为

bash sudo apt-get install openssl-server
实施步骤
建立 A 机器到 B 机器的反向代理 [A 机器上操作]

bash ssh -fCNR <port_b1>:localhost:22 usr_b@B.B.B.B
<port_b1> 为 B 机器上端口,用来与 A 机器上的 22 端口绑定。

建立 B 机器上的正向代理,用作本地转发。做这一步是因为绑定后的 端口只支持本地访问 [B 机器上操作]

bash ssh -fCNL "*:<port_b2>:localhost:<port_b1>' localhost
<port_b2> 为本地转发端口,用以和外网通信,并将数据转发到 <port_b1>,实现可以从其他机器访问。

其中的 *表示接受来自任意机器的访问。

现在在 C 机器上可以通过 B 机器 ssh 到 A 机器

bash ssh -p <portb2> usra@B.B.B.B
至此方案完成。

附:

SSH 参数解释
-f 后台运行
-C 允许压缩数据
-N 不执行任何命令
-R 将端口绑定到远程服务器,反向代理
-L 将端口绑定到本地客户端,正向代理
wingyiu
2015-10-13 11:15:49 +08:00
iptable?
FindHao
2015-10-13 16:36:19 +08:00
```
ssh hello@111.111.111.111 -p 8002 -vvvvv

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /home/hello/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 111.111.111.111 [111.111.111.111] port 8002.
debug1: Connection established.
debug1: identity file /home/hello/.ssh/id_rsa type -1
debug1: identity file /home/hello/.ssh/id_rsa-cert type -1
debug1: identity file /home/hello/.ssh/id_dsa type -1
debug1: identity file /home/hello/.ssh/id_dsa-cert type -1
debug1: identity file /home/hello/.ssh/id_ecdsa type -1
debug1: identity file /home/hello/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/hello/.ssh/id_ed25519 type -1
debug1: identity file /home/hello/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3
```
但是在 vps 上不行呢。怎么也登不上去。这是调试信息。
FindHao
2015-10-13 16:37:10 +08:00
在普通机器上尝试了可以。
在 vps 上就一直卡在上面的状态,最后 time out 。
uuair
2015-10-13 22:27:46 +08:00
你也可以在 a 上运行 autossh -M 33333 -NR 23:*:22 b 的 ip
然后 ssh b 的 ip -p 23
也可以的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/227601

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX