Question

I have what is probably a very simple terminal related question. I'm running Ubuntu 8.10 Intrepid Ibex, using Gnome, and I often open a terminal-based ssh session only to have it dropped at some point later on. Once the session is dropped the terminal becomes unusable, obviously because the network connection has been dropped.

Is there a way to re-initialize the session, or even revert to a working local terminal?

Under Windows, using putty, when this happens I can right-click and select restart session, and do not need to open a new terminal, however under linux my lack of understanding on this subject has lead me to always close the defunct terminal, and restart a new one from scratch. I'd like to learn a new and useful trick if there's one out there.

Also, I found the following post which is worded very similarly to mine,

Automatically (or more easily) reconnect to a screen session after network interruption reconnect-to-a-screen-session-after-network-interr

however, as far as I can tell, this is a different topic.

Was it helpful?

Solution

You want to use your SSH escape. By default it's '~', and ~. will terminate your connection.

The question you linked to is about screen, which is useful for resuming your remote session once you use the escape character to kill your local ssh process and reconnect.

OTHER TIPS

First use ~. to disconnect your ssh connection locally. This gets you back to a working local terminal. You could also you another terminal to kill the appropriate ssh command.

In order to keep your remote state you should use screen as previously suggested.

I recently found out about mosh which is a interesting UDP-based resumable shell client. It uses ssh to initialise the connection, and probably needs mosh installed at the server (and UDP access between the client and server), however it can recover from disconnections and IP changes of the client.

To have your local terminal usable again, you can use the reset command.

To run a command in a virtual terminal you can attach/dettach you can use screen or tmux. Typical usage for screen:

$ screen -S somename
screen$ some-console-command
...
^ad

You detach from screen by typing ctrl+a then d

Then you can list the session and attach to it

$ screen -ls
$ screen -dr somename
screen$
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top