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 ~.
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!
Filed by kargig at 13:16 under Encryption,Internet,Linux,Networking
Tags: connection, escape, escape chars, Linux, ssh, tilde
8 Comments | 120,799 views
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 ~~.
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.
ha!
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.
“(Note that escapes are only recognized immediately after newline.)”
So, if it doesn’t work, try pushing Enter before “~”.
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
Thanks a lot for your comment. Added on the post your “dummy-safe” suggestion.
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).