V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
FindHao
V2EX  ›  SSH

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

  •  
  •   FindHao · 2015-10-13 11:05:30 +08:00 · 6145 次点击
    这是一个创建于 3089 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    5 条回复    2015-10-13 22:27:46 +08:00
    FindHao
        1
    FindHao  
    OP
       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 [email protected]
    <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> [email protected]
    至此方案完成。

    附:

    SSH 参数解释
    -f 后台运行
    -C 允许压缩数据
    -N 不执行任何命令
    -R 将端口绑定到远程服务器,反向代理
    -L 将端口绑定到本地客户端,正向代理
    wingyiu
        2
    wingyiu  
       2015-10-13 11:15:49 +08:00
    iptable?
    FindHao
        3
    FindHao  
    OP
       2015-10-13 16:36:19 +08:00
    ```
    ssh [email protected] -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
        4
    FindHao  
    OP
       2015-10-13 16:37:10 +08:00
    在普通机器上尝试了可以。
    在 vps 上就一直卡在上面的状态,最后 time out 。
    uuair
        5
    uuair  
       2015-10-13 22:27:46 +08:00
    你也可以在 a 上运行 autossh -M 33333 -NR 23:*:22 b 的 ip
    然后 ssh b 的 ip -p 23
    也可以的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2015 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 16:18 · PVG 00:18 · LAX 09:18 · JFK 12:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.