hi cohost, ever get annoyed by ssh sessions hanging and forcing you to kill the process? it doesn't have to be this way, for there is a secret ssh menu the ssh industry has been greedily keeping for themselves!
so how do you access this menu? from within an ssh session, press ↵Enter and type ~?
you should see something like this:
Supported escape sequences: ~. - terminate connection (and any multiplexed sessions) ~B - send a BREAK to the remote system ~C - open a command line ~R - request rekey ~V/v - decrease/increase verbosity (LogLevel) ~^Z - suspend ssh ~# - list forwarded connections ~& - background ssh (when waiting for connections to terminate) ~? - this message ~~ - send the escape character by typing it twice (Note that escapes are only recognized immediately after newline.)
pretty cool!
These sequences are built into the ssh client itself, so they work even if the ssh server or your connection breaks! The most useful one here is ~. which exits the ssh session no matter what. Super useful if you have a session hang!The "command line" lets you set up port forwarding (type help after opening it). Most of the other options are pretty self-explanatory - if you need them you probably understand what they mean.
What about nested ssh sessions? You can use ~~ to send the sequence to the inner client, here's an example:
pinkie@stable:~$ ssh ponyvillestable pinkie@ponyville:~$ ssh manehattenstable > ponyville pinkie@manehatten:~$stable > ponyville > manehatten pinkie@manehatten:~$ Connection to manehatten closed.↵Enter~~. pinkie@ponyville:~$stable > ponyville pinkie@ponyville:~$ ssh manehattenstable > ponyville pinkie@manehatten:~$stable > ponyville > manehatten pinkie@manehatten:~$ Connection to ponyville closed.↵Enter~. pinkie@stable:~$stable
neat!
Okay, a few bonus tricks:
- ssh -C enables gzip compression - even though the documentation states that this is unneccessary on fast networks, I've found that it does wonders for improving latency and responsiveness in many situations, especially when using TUIs or printing out lots of logs.
- ssh -v enables verbose logging (-vv or -vvv if you want more), which is useful on a slow connection or when connecting to a slow machine (eg a Raspberry Pi). It lets you figure out whether a connection is hanging (eg host down) or just being slow.
- ssh -D 1234 creates a SOCKS proxy on your localhost:1234 that lets you use the server's network. Quite handy if you need to mess around in the LAN of the server, or if you need a quick DIY VPN in a pinch.
alright that's all, i hope you picked up something useful from this post! it's my first time posting anything of this kind so i hope you like it!
