Restore SSH session
Solution 1
As suggested above, in the future you can use screen to prevent such thing. A short explanation on how to use screen:
screen -S compiling_stuff
- Do stuff here. e.g
./configure
- If connection is closed for some reason you can reconnect to the server and issue
screen -r comp
- You can detach the screen session yourself too by pressing
CTRL+A+D
Good luck
Solution 2
screen
is the best to start a command in a terminal that will be kept when you disconnect from it (either on purpose, ctrl+a d, or because connection dies, etc).
HOWEVER you CAN re-attach a running process (ex: the shell of your running session, if still running) to your current terminal (ie, re-attach stdin, stdout, keyboard, but also make the new terminal the controlling terminal for that process) using: reptyr
For the best of both worlds: install screen
, start it, and then re-attach that process in that screen sessions with reptyr
^^
Solution 3
You can't. In the future, you can prevent something like this with using screen
or tmux
, which where created to allow to reconnect to a session after a disconnect.
Solution 4
Just thought I would mention http://mosh.mit.edu/
Remote terminal application that allows roaming, supports intermittent connectivity, and provides intelligent local echo and line editing of user keystrokes.
Mosh is a replacement for SSH. It's more robust and responsive, especially over Wi-Fi, cellular, and long-distance links.
Solution 5
Use screen
via ssh to reconnect later to your session.
As far as I know there is no way to reconnect to a closed ssh-session.
Related videos on Youtube
Arash Mousavi
Updated on September 18, 2022Comments
-
Arash Mousavi almost 2 years
I have connected to my server via SSH and created a process, but suddenly my internet connection got disconnected. I know that the process is going on, but how can restore previous session to see the progress of it?
-
user3621202 over 11 yearsOliver, how is it possible to re-attach to running process? Could you gimme a hint please?
-
Olivier Dulac over 11 years@archer : hint : follow the link ^^ (end of my 2nd paragraph)
-
Olivier Dulac over 11 years@archer : but screen is simpler: once runnign in screen, ctrl+a d : detach from screen (and go home). then to re-attach to screen: "screen -r" (or a more complex way, if things get stuck). To differentiate amongst many screen sessions, give them a name.
-
Olivier Dulac over 11 years+1 for the heads up, I never heard of that tool before!