May 10, 2013

What if your connection drops while you are in the middle of SSH?

If your connection drops in the middle of an ssh session, the TTL of your session will terminate your job running via that session after a while. To avoid
use 'screen' or 'tmux'.

  • ssh into your remote box. type screen Then start the process you want.
  • Press Ctrl-A then Ctrl-D. This will "detach" your screen session but leave your processes running. You can now log out of the remote box.
  • If you want to come back later, log on again and type "screen -r" This will "resume" your screen session, and you can see the output of your process.

    To get the same functionality as explained in the post with the most votes you would need to do the following:

    • ssh into the remote machine
    • start tmux by typing tmux into the shell
    • start the process you want inside the started tmux session
    • leave/detach the tmux session by typing Ctrl-B and then D
    You can now safely logoff from the remote machine, your process will keep running inside tmux. When you come back again and want to check the status of your process you can use tmux attach to attach to your tmux session.
    If you want to have multiple session running side-by-side you should name each session using Ctrl-B and $. You can get a list of the currently running sessions using tmux list-sessions.
According to wikipedia: 'screen' latest release is in August 2008 and 'tmux' latest release is in March 2013.

No comments:

Post a Comment