TIL: SSH Disconnect Sequence and Escape Characters
If you use SSH over an unstable connection, this article will be a great tip on how to quit SSH while keeping the host terminal open and to also find more details about other features in SSH.
Motivation
I use SSH to connect with remote servers. Over a bad connection where the connection can drop. When the connection drops, the SSH client becomes unresponsive for a little while because it is unsure of the connection state and will try to keep reconnecting. During this period, SSH will receive keys, but will not respond.
If I want to disconnect during this state, it is impossible as any input is being queued. To disconnect from an unresponsive SSH connection, shutting down the whole terminal program is how I usually accomplish this, which normally is not hard, but on an iPad terminal, it gets annoying pretty fast.
Command
The quick way to disconnect SSH is to enter this key combination:
Sequentially press the Return, tilde, and period keys.
How I found it
Originally, a coworker told me about this nifty trick and I found it a great way to disconnect hanging SSH sessions.
Learning more
When I read this answer, by my favorite Python programmer Aaron Hall, I found there are more escape characters for SSH. These are described in detail in the SSH man page:
There’s a lot more great information on the SSH man page, like configuration files, or how to setup a VPN over SSH. It’s quite impressive the amount of documentation SSH has.
Conclusion
I learned how to gracefully disconnect a hanging SSH session with
simple key commands: <Return> ~ .
and also learned more features of
SSH through its UNIX man page.