SSH 跳转主机,到最终主机,然后是 tmux

SSH to jump host, to final host, then tmux

在我的 ssh 配置中,我有

Host jumpHostNick
     HostName jumphost.com
     User username

Host finalHostNick
     User username
     ProxyCommand ssh jumpHostNick nc finalHostURL 22

我想在它到达最终主机时通过 运行 tmux attach -d 来补充这一点。这可能吗?

使用 -W 而不是 netcat:

Host jumpHostNick
     HostName jumphost.com
     User username

Host finalHostNick
     User username
     ProxyCommand ssh -W finalHostURL:22 jumpHostNick

如果你想运行tmux attach -d,你还应该添加到finalHostNick:

RequestTTY yes

然后使用 ssh finalHostNick -t tmux attach -d 连接,或者只设置 bash 别名:

alias ssh-final='ssh finalHostNick -t tmux attach -d'

在你的 ~/.bashrc