Shell fun: escape ssh(1)
This shell fun post really needs a hat tip to kargig for his SSH Escape Characters post. I had read about ssh escape characters ages ago and never considered them very useful. kargig's post inspired me to experiment a bit more and finally (with a default setup that works for me and 2 nice use cases for me) I start to like those hidden beasts...
First of all, if you jack in to other servers using the default OpenSSH configuration, ~ is already set up as the default ssh escape character. But there is a trick to it: If you just press ~ while ssh-ing to another system, nothing happens. That is a Good Thing(TM), because otherwise I would get confused whenever I wanted to spy on Wu by typing cd ~wu. If you want to get into the "hidden ssh menu", you have to press "Return" (aka "Enter" for some people) first, then the tilde ~.
And voilà! So press Enter, followed by ~? and you will see this nice help menu:
kronos /home/betabug$ ~? Supported escape sequences: ~. - terminate connection ~B - send a BREAK to the remote system ~C - open a command line ~R - Request rekey (SSH protocol 2 only) ~^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.)
The characters that form this output actually come from your local system. As kargig mentions, one he gets out of it is to terminate hanging sessions - I don't much have that problem (maybe I should start to use Linux too...), but I have two other nice uses for this stuff:
Adding a port forwarding to an existing connection. I.e. to add a forwarding for VNC to an existing connection, do ~C and on the prompt do:
ssh> ? Commands: -L[bind_address:]port:host:hostport Request local forward -R[bind_address:]port:host:hostport Request remote forward -KR[bind_address:]port Cancel remote forward ssh> -L 5900:127.0.0.1:5900My other use is coupled with ssh-agent(1): When I have ssh-agent set up to "cache" my ssh private key and I use a terminal window to log in to a server, I often want to do a short job with the ssh-key too (like scp'ing a file or doing a quick login to another machine). Now I can temporarily background my main ssh connection and do my job:
kronos /home/betabug$ ~^Z [suspend ssh] Suspended [briareus:~] betabug% scp important_file.tgz lamesrv: [briareus:~] betabug% fg kronos /home/betabug$
Which sometimes is a nice little time saver!