117 ssh bash git command-line tunnel
SSH 隧道让我很困惑。我想知道我是否可以在 Linux 中做到这一点。
我有3台机器..
A. My local machine at home.
B. Machine at work that I can SSH into (middle man).
C. My desktop at work that I can only SSH into from machine B.
Run Code Online (Sandbox Code Playgroud)
所以我可以从 A -> B 和 B -> C 进行 SSH,但不能从 A -> C 进行 SSH。
有没有办法设置从 A 到 B 的 SSH 隧道,所以当我运行其他 SSH 命令时,它们只能在我的本地机器 A 上工作?我基本上是在尝试将 git repo 从工作克隆到家(并且我无法在机器 B 上安装 git)。
此外,一旦设置.. 我将如何取消设置?
eph*_*ent 137
将其.ssh/config
放在 hostA 上的文件中(有关详细信息,请参阅man 5 ssh_config):
# .ssh/config on hostA:
Host hostC
ProxyCommand ssh hostB -W %h:%p
Run Code Online (Sandbox Code Playgroud)
现在以下命令将自动通过 hostB 隧道
hostA:~$ ssh hostC
Run Code Online (Sandbox Code Playgroud)
您可能希望添加诸如-oCiphers=arcfour
和-oClearAllForwardings=yes
加快速度的选项,因为ssh
在内部包装在ssh
计算上更昂贵并且额外的努力和包装器在隧道传输已经加密的流量时不需要那么安全。
如果您使用的 OpenSSH 早于 5.3,则该-W
选项不可用。在这种情况下,您可以使用 netcat ( nc
)实现上述内容:
ProxyCommand ssh hostB nc %h %p # or netcat or whatever you have on hostB
Run Code Online (Sandbox Code Playgroud)
小智 7
编辑:这是错误的方法。请参阅ephemient 的答案。这个答案会起作用,但可能不太安全,而且绝对不那么棒。
听起来您想要如下解决方案:
ssh -L localhost:22:machinec:22 machineb
Run Code Online (Sandbox Code Playgroud)
这将为您提供一个 shell machineb
。别管这个;最小化终端窗口。
现在,只要你做的SSH连接localhost
,你实际上将连接到machinec
通过machineb
。完成隧道后,只需关闭运行上述命令的终端即可。
请注意,您需要超级用户权限才能运行该命令。
小智 6
对于交互式 shell,您可以使用这个简单的命令:
ssh -J <user>@<hostB> <user>@<hostC>
Run Code Online (Sandbox Code Playgroud)
-J 选项用于jump。
或者,由于OpenSSH 7.3引入了一个ProxyJump
指令:
Host final
ProxyJump intermediate
Run Code Online (Sandbox Code Playgroud)
在示例中:
Host intermediate
Hostname 10.0.0.42
User root
Host final
Hostname final.destination.com
User foo
ProxyJump intermediate
Run Code Online (Sandbox Code Playgroud)
然后ssh final
会跳过中间机。
听起来您想要 A 上的 shell 别名导致 C 上发生 ssh
归档时间: |
|
查看次数: |
56334 次 |
最近记录: |