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 ~.
Dummy-safe: So to get it to escape press[alt gr] + [~] two times and then [.]
If that doesn’t work, try pushing Enter before “~”.

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!

8 Responses to “SSH Escape Characters”

  1. bvr
    July 1st, 2006 | 12:24
    Using Mozilla Firefox Mozilla Firefox 1.5 on Linux Linux

    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 ~~.

  2. tavl
    October 25th, 2008 | 07:41
    Using Mozilla Firefox Mozilla Firefox 2.0.0.14 on Linux Linux

    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.

  3. ha
    September 14th, 2010 | 13:49
    Using Google Chrome Google Chrome 6.0.475.0 on Windows Windows XP

    ha!

  4. October 24th, 2010 | 19:21
    Using Mozilla Firefox Mozilla Firefox 3.6.10 on Ubuntu Linux Ubuntu Linux

    Thanks, this was very helpful.

    Someone’s been running a number of attacks against my server and it went down while I was ssh’d in trying to fix it. It’s nice to know there’s a way to close return to a command shell when everything stops working.

  5. nbdy
    November 18th, 2010 | 05:31
    Using Mozilla Firefox Mozilla Firefox 3.6.12 on Windows Windows Vista

    “(Note that escapes are only recognized immediately after newline.)”

    So, if it doesn’t work, try pushing Enter before “~”.

  6. February 25th, 2011 | 21:50
    Using Mozilla Firefox Mozilla Firefox 3.6.13 on Ubuntu Linux Ubuntu Linux

    At first I didn’t see the dot. “~.”

    (dummy-safe): So to get it to escape press [alt gr] + [~] two times and then [.]

    Additional escape sequences for ssh can be found in the man page:

    http://manpages.ubuntu.com/manpages/dapper/man1/ssh.1.html

  7. February 26th, 2011 | 10:20
    Using Mozilla Firefox Mozilla Firefox 3.6.13 on Linux Linux

    Thanks a lot for your comment. Added on the post your “dummy-safe” suggestion.

  8. December 2nd, 2015 | 15:07
    Using Mozilla Firefox Mozilla Firefox 42.0 on Ubuntu Linux Ubuntu Linux

    Nice tutorial! If you want to learn about SSH escape characters on Ubuntu Server you can take a look at SSH escape characters on Ubuntu Server (video tutorial).

Leave a reply