Reconnect or login to existing session
Scenario / Question:
I logged into an ssh session on a remote computer and lost my connection, how do I reconnect to the same session ?
This trick will help users and system administrators become less frustrated when working on remote systems, and not worry about losing their connection to the remote system.
Solution / Answer:
Typically when breaking the connection to the remote host system would kill the running process, and you lose your remote session.
Using a utility called “screen” you can preserve your session even if you disconnect from the remote host system.
Screen
After you ssh or login to a session invoke the following command and replace “session_name” with the name you want to call this session:
screen -S "session_name"
To manually disconnect from this session, but keep it alive so you can reconnect later. For example if you know you have to reboot your workstation.
holding CTRL, then press A, and then D
To reconnect to an existing session run the command and replace “session_name” with the name you called the session earlier:
screen -r "session_name"
To test that this will work in the event of an unforeseen disconnection, close your session window without running the above disconnect command.
Now ssh or login back to the remote host and run the reconnect command and replace “session_name” with the name you called the session earlier:
screen -r "session_name"



Thanx for posting!