【问题标题】:How to write shell script to tunnel via 2 computers to third one如何编写 shell 脚本以通过 2 台计算机隧道连接到第三台计算机
【发布时间】:2011-09-30 04:33:06
【问题描述】:

我是 unix/linux 的新手,在尝试通过 ssh 隧道连接到我大学的计算机时遇到问题。

我正在尝试访问我学校网络上的计算机 A。但除非我已经进入学校网络,否则无法访问它。我可以 ssh 到计算机 B,然后 ssh 到计算机 A。假设计算机 C 只能通过计算机 B 访问,我将如何制作一个可以为我执行此操作的 shell 脚本?

到目前为止,我通过 B 隧道连接到计算机 A,但无法到达 C。 我试过这个

    ssh -t user@computerB 'ssh user@computerA' 'ssh user@computerC'
    sh -t user@computerB "ssh user@computerA 'ssh user@computerC'"

我做错了什么

【问题讨论】:

  • 您的示例与您的场景不匹配,您说 C 只能从 B 到达,因此您不需要通过 A 到达 C;直接去B到C就好了。

标签: linux unix shell ssh tunneling


【解决方案1】:

似乎对我有用。显然你必须使用 -t 来强制每次跳转的 ptty 分配:

jcomeau@intrepid:~/rentacoder/peppe/dentalcam$ ssh -t www "ssh -t tek 'ssh -t www'"
Linux unixshell.jcomeau.com 2.6.18.8 #1 SMP Mon Nov 22 15:26:09 EST 2010 i686 GNU/Linux

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
No mail.
Last login: Thu Jul  7 02:03:30 2011 from c-76-103-110-80.hsd1.ca.comcast.net
jcomeau@unixshell:~$ logout
Connection to www closed.
Connection to tek closed.
Connection to www closed.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 2012-02-28
    • 2019-07-18
    相关资源
    最近更新 更多