I commonly have 4-6 ssh sessions open at once, and when I lose my VPN connection, they just sit there until their timeout hits. I was looking for a way to stop the session, and CTRL-C, CTRL-D, CTRL-Z and everything inbetween didn’t work.
I found salvation in: ‘~.’
That will exit your session no problem.
Related posts:
#1 by Alex on October 20, 2008 - 10:08 pm
Quote
Wow. That’s really weird, but really helpful, too. I wonder if it will work when I start a KDE app in a ssh session with X tunneling, which always makes ssh hang on exit. I hope I can avoid mistyping ~/ when using ssh. At least it only works under specific circumstances.
#2 by admin on October 20, 2008 - 10:43 pm
Quote
Yeah if I type ~.RETURN~. it exits, not sure on all systems if it is just ~.CR or if it is ~.CR~.
#3 by jetsaredim on October 20, 2008 - 11:02 pm
Quote
I had a problem with my ssh sessions getting screwed up during timeouts. Finally decided to really make use of screen. Now I can connect/disconnect from the VPN and not lose days worth of work or context.
#4 by karl on October 20, 2008 - 11:31 pm
Quote
The CR is required before the ~
CR~.
#5 by Aleksey on October 21, 2008 - 12:55 am
Quote
Cool! I’ve been annoyed with that for quite a while. I’ll try it next time I have that problem.
#6 by Jeff Schroeder on October 21, 2008 - 8:42 am
Quote
@admin: The “proper” key sequence is:
\r~.
Where \r is a carriage return (often mistaken for \n but not the same).
Here is another trick for you to add. Say you ssh to an ssh gateway and then on from there to a mysql server. Being the pig it sometimes is, mysql goes nuts and for some reason the oom-killer doesn’t nuke it so the box effectlively hangs. Now, how do you disconnect from it without disconnecting from the ssh gateway?
If you were to do:
\r~.
It would disconnect you from both. So… Try:
\r~~.
If you ssh to a third box and only want to disconnect from it, try:
\r~~~.
You get the idea.
—
Jeff Schroeder
http://www.digitalprognosis.com/blog
#7 by Joseph on October 21, 2008 - 7:26 pm
Quote
~?
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 (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.)
#8 by Joseph on October 21, 2008 - 7:31 pm
Quote
frickin’ a. Your javascript is broken. Namely, after enabling javascript (after it already eated one of my posts because I didn’t have it enabled(!!!)) it ate my post because it told me to “answer the question!” So, I did. Or I had thought that I did. Rather, whenever I clicked on the “please add and ” input field, it *immediately* shifted focus to the Website field! I could only post what I just did after (apparently unknowingly) re-pasting the help text I highlighted and then holding the mouse button down in the “Please add and ” input field and typing in the answer.
WTF!
The (re-re-paraphrased) post:
~ is useful for more than just terminating the connection. ~? presents the help text:
~?
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 (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.)
~# is great to see what forwarded connections are preventing you from exiting from the other host, and ~& is great if you want to keep working with the forwarded connections still going.