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"


Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
Fabio Milano has written 79 articles for us. Fabio Milano is a certified RHCE, MCP, and CFOI. He runs an IT consulting and services company called RDS Support inc. Website:http://www.rdssupport.com
The information provided is for educational purposes only. All content including links and comments is provided "as is" with no warranty, expressed or implied. Use is at your own risk and you are solely responsible for what you do with it.

1 Comment so far

  1. Dennis van der Pool on July 5th, 2009

    Thanx for posting!

Leave a reply