24/01/2006
SSH Escape Characters
I am sure a LOT of people reading this blog use ssh in their everyday work/life/etc. I am not sure though how many of you have heard of ssh EscapeChar unless you’ve read the ssh_config file (and even if you have done so, did you pay any attention to it ?). So what can you do with EscapeChar ? not a lot, but certainly very usefull stuff.
My most frequent problem with ssh is sessions that sometimes they don’t end as they are supposed to. You logout from the remote system and you never get a prompt on yours because something has stuck somewhere, sometime. Wouldn’t you wish there was an escape sequence to end this suffering, like telnet’s ctrl+] ? Well there is! Just edit your client’s ssh config file (/etc/ssh/ssh_config for gentoo) and add to the end:
EscapeChar ~
now try ssh to a host and when you are in, try this: ~?. You will see a list of helpfull options. The solution to the previous described problem of stale connections is ~.
What’s also very helpfull is the ability to start/end portforwarding during an active ssh session! Say you have opened an ssh connection to a host and you now have to portforward a port, what do you do ? New ssh connection with -L/-R options ? nope! You just press ~C and do what you want from the ssh “command shell”.
enjoy!
Filed by kargig at 13:16 under Linux, Networking
2 Comments | 8,313 views


Using
the ~? tells you to type ~~ to send a single escape char.
this means when you’re connected over ssh via another host, and you would like to end the ’stuck’ connection from the next host, instead of your local ssh session, just type ~~.
Using
I was reading the manpage, when found the “ESCAPE CHARACTERS” section. Tried the combinations without luck, but your suggestion to add the ‘EscapeChar’ entry to my ssh_config file solved the problem, thanks.
Btw, if you don’t have enough permissions to edit /etc/ssh/ssh_config (it’s there, @ slackware, too), or don’t wanna affect all the other users with the changes, ssh has a “per-user” config file. It’s located at $HOME/.ssh/ssh_config. Note that you may have to create it.