How to recover a shell after a disconnection

There is no way, but to prevent this I like using tmux. I start tmux, start the operation and go on my way. If I return and find the connection has been broken, all I have to do is reconnect and type tmux attach.

Here's an example.

$ tmux
$ make <something big>
......
Connection fails for some reason
Reconect

$ tmux ls
0: 1 windows (created Tue Aug 23 12:39:52 2011) [103x30]

$ tmux attach -t 0
Back in the tmux sesion

The recommendations for tmux and screen are both good suggestions. They imply the answer to your question, but don't actually state it. The answer to the question is: there is no way. If you login via ssh, the shell is ended when the connection drops. The work-around is to login and immediately start a virtual terminal of some kind (this can be done with tools like dtach, abduco, tmux, or screen). When the connection drops, the shell you are in is ended, but you can open a new shell and reconnect to the virtual terminal that is running the shell in which you are actually doing your work.


As William said, the short answer is no, there is no way. To prevent this you could use the screen command before you lose connection