在我工作的环境中,我们使用隧道通过 SSH 连接到各种服务器。例如,我将 'ssh -p XXXXX username@localhost' 访问服务器。
如果端口总是相同的,我可以这样做,我会完成:
Host somehost
User bryan
Hostname localhost
Port 12345
ProxyCommand ssh -p 2218 bryan@first.server.com -W %h:%p
Run Code Online (Sandbox Code Playgroud)
但是,如果隧道关闭并恢复,所使用的端口可以并且将会改变。这不是我有能力改变的——它内置于基础设施中。所以,我写了一个程序来查找当前端口。但我也不知道如何:
a) 运行该程序并使用 %p 变量的输出;或者 b) 在 first.server.com 上运行一个 cron 作业来写出一个带有端口的文本文件,或者设置一个环境变量,或者其他东西。
实际上,我想这样做。是否可以?
主持某位主持人 用户布莱恩 主机名 localhost 端口`sh get_port_for_somehost.sh` ProxyCommand ssh -p 2218 bryan@first.server.com -W %h:%p
我现在唯一能想到的就是在我的笔记本电脑上运行一个程序,它在查询当前的端口后重写我的 .ssh/config,但我不想这样做。