Restore SSH session

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?


Solution 1:

As suggested above, in the future you can use screen to prevent such thing. A short explanation on how to use screen:

  1. screen -S compiling_stuff
  2. Do stuff here. e.g ./configure
  3. If connection is closed for some reason you can reconnect to the server and issue screen -r comp
  4. 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 ^^