16

This is a very simple problem. I use gnome-terminal to SSH to other machines every day. I do this on a laptop which I carry around the office, so I am constantly switching between wired and wireless networks. When this happens my SSH sessions drops off and the terminal freezes.

Why does this happen (the freezing, not the session dropping) and is their a way to prevent it? I know I can get around this by logging off from the remote server before I know I want to disconnect my laptop from Ethernet.

It's annoying because I have to manually close the terminal session after it has frozen which pops up a dialogue box and I also lose the title of the session - all very time consuming. It would be much better if the ssh session just got killed and it returned me back to the local bash prompt.

1
  • 1
    Try pressing Ctrl + D
    – a06e
    Aug 18, 2014 at 14:07

2 Answers 2

24

The session will eventually time out and disconnect; this will happen faster if you configure ServerAliveInterval and ServerAliveCountMax in ~/.ssh/config. To force an immediate disconnect, Return~..

7

Without getting into the why of it, here's how you fix it:

~.

that's tilde-dot. Press those two keys, one after another, and that will disconnect from the hung ssh session and give you back your terminal. Yay!

1
  • I would add that before pressing ~. you press Return as the keys should be sent in their line by themselves and it could be dirty so you assure a new line by pressing return before typing the rest.
    – PhoneixS
    Mar 30, 2023 at 7:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .