Keep Terminal Sessions Running with screen or tmux

If you need a long-running shell session to survive an SSH disconnect, use a terminal multiplexer such as screen or tmux. Both let you detach from a session and reconnect later.

Using screen

screen -S work

Detach with Ctrl-A then D. Reattach later with:

screen -r work

Using tmux

tmux new -s work

Detach with Ctrl-B then D. Reattach with:

tmux attach -t work

For unattended production jobs, a systemd service, scheduler, batch system, or job runner is often better than relying on a personal terminal session.

Leave a Comment