Linux

在一個命令中退出所有 SSH 連接並關閉 PuTTY

  • February 24, 2022

有沒有辦法退出所有 SSH 連接並“一次性”關閉PuTTY ?我在 Windows 7 中工作,並使用 PuTTY 通過 SSH 連接到各種 Linux 主機。

我發現自己工作方式的一個例子:

SSH to host1 with PuTTY...
banjer@host1:~> #...doin some work...ooh! need to go check something on host8...
banjer@host1:~> ssh host8
banjer@host8:~> #...doin some work...OK time for lunch. lets close putty...
banjer@host8:~> exit
banjer@host1:~> exit
Putty closes.

如上所述,有什麼方法可以從 host8 一次性關閉 PuTTY?有時我發現自己的深度可達 5 或 10 個主機。我意識到我可以點擊 X 關閉 PuTTY 視窗,但我喜歡使用 exit 命令確保我的 SSH 連接正確關閉。我也意識到我在詢問如何增加懶惰的技巧。我會把它寫成“我怎樣才能更有效率”。

嘗試使用ssh連接終止轉義序列。

ssh會話中,輸入~.(波浪號)。鍵入時您不會看到這些字元,但會話將立即終止。

$ ~.
$ Connection to me.myhost.com closed.  

man 1 ssh

The supported escapes (assuming the default ‘~’) are:
~.      Disconnect.
~^Z     Background ssh.
~#      List forwarded connections.
~&      Background ssh at logout when waiting for forwarded 
        connection / X11 sessions to terminate.
~?      Display a list of escape characters.
~B      Send a BREAK to the remote system (only useful for SSH protocol
        version 2 and if the peer supports it).
~C      Open command line.  Currently this allows the addition of port 
        forwardings using the -L, -R and -D options (see above). It also
        allows the cancellation of existing remote port-forwardings using 
        -KR[bind_address:]port.  !command allows the user to execute a 
        local command if the PermitLocalCommand option is enabled in
        ssh_config(5).  Basic help is available, using the -h option.
~R      Request rekeying of the connection (only useful for SSH protocol 
        version 2 and if the peer supports it).

引用自:https://unix.stackexchange.com/questions/41682