Avoiding issues when disconnected using ssh

To solve issues with broken pipes etc when connecting to remote boxes. Very useful, especially when installing things or running long commands.

From http://serverfault.com/questions/19634/how-to-reconnect-to-a-disconnected-ssh-session:

GNU Screen allows you to have a ‘screen session’ on the remote box that you can run multiple commands in, via multiple ‘screen windows’. This will simply detach if your parent SSH connection dies, keeping all the subprocesses running within it alive and well.

Basics are:

  • Start a screen session (on your remote host):
    $ screen
  • Detach from your screen session: CTRL-A, d
  • Re-attach to your screen session after logging back in again:
    $ screen -d -r
  • Open another screen ‘window’: CTRL-A, c
  • Cycle through you open screen windows: CTRL-A, space