Day 57: Tmux, Stayin' alive

29 Sep 2017

When you execute long-running tasks on remote servers, SSH connection may break (poor network conditions, out of battery…). Because the running process is attached to your session, it may be interrupted at the same time.

To prevent your terminal to lost current work, you can use screen (old) or tmux (modern) on the remote server.

Man

Tmux runs a daemon on the remote machine. Any commands executed inside tmux will not be attached to your tty, but to the daemon.

Example

$ ssh 1.2.3.4
[root] $ tmux
[root ~ tmux] $ sleep 3600

Then kill your terminal or open a new one !

$ ssh 1.2.3.4
[root] $ tmux list-sessions
0: 1 windows (created Fri Sept 29 16:42:42 2017) [181x79]
[root] $ tmux attach

# And you see this:
[root ~ tmux] $ sleep 3600

Please note that your didn’t need to execute sleep 3600 here because it is still running \o/