我可以将这些 SSH 隧道命令组合成一个命令吗?
Can I combine these SSH tunneling commands into one command?
我有一个通过 SSH 访问特定服务器的两步解决方案:
第 1 步,在 bash 中:
ssh -L 127.0.0.1:5000:server2.com:22 server1.com
第 2 步,在新的 bash 会话中:
ssh -P 5000 127.0.0.1 # This gets me into server2.com
Q1:有什么方法可以将这两个命令合并为一个 ssh 命令,并且...
Q2:我可以在我的 ~/.ssh/config
中为此连接设置一个主机条目吗(允许我只输入例如 ssh my-tunnel
)?
我想这归结为以某种方式链接主机。我是新手,不太明白这一点...
我偶然发现 this question 并且对 ssh 支持 跳转主机.
感到惊讶
您可以使用单个命令连接到目标服务器,而 ssh 将负责中间跃点。
ssh -J server1.com server2.com
-J [user@]host[:port]
Connect to the target host by first making a ssh connection to the jump host and then establishing a TCP
forwarding to the ultimate destination from there. Multiple jump hops may be specified separated by
comma characters. This is a shortcut to specify a ProxyJump configuration directive
这里是SSH配置对应的跳转主机配置:
Host jumphost
Hostname server1.com
User $YOUR_USERNAME
Port 22
Host my-tunnel
Hostname server2.com
User $YOUR_USERNAME
Port 22
ProxyJump jumphost
...启用命令:ssh my-tunnel
我有一个通过 SSH 访问特定服务器的两步解决方案:
第 1 步,在 bash 中:
ssh -L 127.0.0.1:5000:server2.com:22 server1.com
第 2 步,在新的 bash 会话中:
ssh -P 5000 127.0.0.1 # This gets me into server2.com
Q1:有什么方法可以将这两个命令合并为一个 ssh 命令,并且...
Q2:我可以在我的 ~/.ssh/config
中为此连接设置一个主机条目吗(允许我只输入例如 ssh my-tunnel
)?
我想这归结为以某种方式链接主机。我是新手,不太明白这一点...
我偶然发现 this question 并且对 ssh 支持 跳转主机.
感到惊讶您可以使用单个命令连接到目标服务器,而 ssh 将负责中间跃点。
ssh -J server1.com server2.com
-J [user@]host[:port] Connect to the target host by first making a ssh connection to the jump host and then establishing a TCP forwarding to the ultimate destination from there. Multiple jump hops may be specified separated by comma characters. This is a shortcut to specify a ProxyJump configuration directive
这里是SSH配置对应的跳转主机配置:
Host jumphost
Hostname server1.com
User $YOUR_USERNAME
Port 22
Host my-tunnel
Hostname server2.com
User $YOUR_USERNAME
Port 22
ProxyJump jumphost
...启用命令:ssh my-tunnel