I am working with Linux quite a lot and sometimes I face this situation:
I have a terminal with ssh connected to a remote server and after a while the ssh connection gets frozen on a remote side for some reasons. Now what? I used to find the PID of the ssh process in another terminal and then used kill -9 PID. This method looked a bit too "brute force" just for closing the broken ssh session and I was looking for a more "elegant" solution.
Like when I am telnet_ed somewhere, I can use the CRTL+] key sequence as a escape character to break the connection.
I found a similar solution for ssh:
[enter]~.
First press the Enter key, then tilde, and then add a dot and your ssh session will be closed and you can continue your work in back in freed terminal.
January 1, 2008
Close your frozen ssh session
Labels: linux
Posted by Jozef Janitor at 1/01/2008 09:55:00 PM
Subscribe to:
Post Comments (Atom)
THANK YOU THANK YOU THANK YOU!! I have been wondering about this for years! I am a bit fanatical about archiving my bash history, so I always want to kill frozen ssh connections (usually the result of closing my laptop) from a separate [Gnu] screen window and exit bash properly. When I have 10+ windows in screen with different ssh connects in N-1 of them, it is a pain.
ReplyDeleteOh, and if that sounds careless, consider that I run screen both locally and remotely. That way anytime I reconnect to a server I see the terminal exactly the way I left it. (Just be careful not to leave yourself "sudo su -"ed, that's poor security.) If you aren't familiar with Gnu Screen, get informed.
Many thanks Jozef, this is the best tip I got since a long time
ReplyDeleteWorked a charm. Thank you!
ReplyDeleteAh, well... didn't work for me, but my problem is worse.
ReplyDeleteI have a screened ssh session stuck within an ssh session. I tried to log out of it, and it got stuck. No escapes work. The only way I know of to kill it is to kill screen session itself, which I don't want to do.
Any elegant way of fixing this?
@Anonymous: well, maybe screen is doing some characters translation (like the CRTL+A has a special use with screen), and therefore you might want to use a slightly different keys combination.
ReplyDeleteOr ... if you can SSH to that server once again (open a new session), then just use the pretty good old way: find your fronzen SSH's PID and kill it with "kill -9 $PID".
Thank you a lot. This was bothering me for months.
ReplyDeleteThanks a lot!
ReplyDeleteThanks! I've been killing them for years. I should have googled ages ago.
ReplyDelete@RichardBronosky
Regarding the keeping of your bash history - try adding PROMPT_COMMAND='history -a' to your .bashrc. You'll never lose another command again! ;-)
I love your blog, you should add an RSS feed feature so I can get automatic notifications of new blogs. If you set one up please email me! i will bookmark you for now. Again Excellent Blog!
ReplyDelete_________________
get vpn
This has been bothering me for years. I'm very happy that I googled it today :)
ReplyDeleteThank you very much!
The most difficult is finding a reliable vpn service that can maintain total anonymity in all Internet connections and avoids the interception of all Internet communication all of this using the internet connection at the maximum speed with no visible delay..
ReplyDeletePerfect trick!
ReplyDeleteThank you :)
WOW...Many thanks! Worked great and something I always wanted to know...and needed.
ReplyDeleteThankS!
ReplyDelete"Everything I always wanted to know about ssh but was afraid to ask...!"