Sessions that simply survive an SSH disconnect
Anyone who starts long running processes on a remote server while relying on a plain SSH terminal risks losing all progress the moment the connection drops. tmux and GNU Screen solve this by decoupling sessions from the actual terminal and keeping them running in the background, whether the connection wobbles or the laptop lid closes.
Table of Contents
- 1. Why a terminal multiplexer is necessary at all
- 2. tmux and Screen: core concepts compared
- 3. The first tmux session: attach, detach, persistence
- 4. Windows and panes: the screen as a workspace
- 5. Configuration: tuning tmux.conf for daily use
- 6. Automating and scripting session setups
- 7. GNU Screen in practice: when tmux is not available
- 8. Common pitfalls in daily server work
- 9. tmux versus Screen compared directly
- 10. Summary
- 11. FAQ
1. Why a terminal multiplexer is necessary at all
Anyone who works regularly over SSH on remote servers knows the problem: a WiFi interruption, a laptop going to sleep, or simply a network timeout, and the entire SSH connection drops. Without tmux or Screen, every process running in that terminal dies at that moment, including ongoing migrations, log monitoring, or interactive debugging sessions. That is not just annoying, it is a genuine risk to production operations for anything that runs longer than a few minutes.
A terminal multiplexer such as tmux solves this problem structurally by running its own session on the server, completely independent of the SSH connection. The SSH connection is then only used to attach to that session, not to execute the actual work. If the connection drops, the session keeps running unaffected, with all windows, processes and terminal history intact, until you attach to it again. This behavior is exactly what makes tmux essential equipment for any remote work that takes longer than a couple of minutes.
Beyond pure resilience, a terminal multiplexer brings a second, often underestimated benefit: the ability to manage multiple windows and split areas within a single SSH connection. Instead of opening a new SSH connection for every parallel task, you split the screen into several panes and keep log output, editor and shell visible at the same time. For everyday server administration and development, that is the actual productivity gain of tmux.
2. tmux and Screen: core concepts compared
Both tools, tmux and GNU Screen, follow the same basic principle: a server process keeps the actual session alive while any number of terminal clients can connect to it or disconnect from it. The technical terms for this are detaching and attaching. You start a session, work inside it, detach it from the current terminal with a key combination without ending it, and later, even from a different machine, reconnect to that exact same session.
tmux is the younger implementation of this concept and was developed starting in 2007 with the goal of offering more cleanly structured code and a more consistent operating concept than Screen. The central terms in tmux are session, window and pane: a session can contain several windows (comparable to browser tabs), and each window can in turn be divided into several panes (split areas). Screen has technically similar concepts, but without the native, well documented pane management that tmux had built in from the start.
An important practical difference lies in configurability and ecosystem. tmux uses its own, readable configuration language in the file ~/.tmux.conf and comes with an active plugin landscape, for example the Tmux Plugin Manager. Screen, on the other hand, has been preinstalled on practically every older Unix system for decades and is therefore often the only option on minimal systems where tmux cannot or should not be installed. For new projects, tmux is generally the right choice, while Screen remains an important tool for legacy environments.
3. The first tmux session: attach, detach, persistence
Getting started with tmux begins with the command tmux new -s name, which creates a named session. The name matters because you can later find and attach to that exact session again, even while several sessions run in parallel. Inside the session the shell behaves as usual, with the crucial difference that anything started here keeps running independently of the current SSH client.
Detaching a session happens with the key combination Ctrl+b followed by d. The prefix Ctrl+b is the default trigger for all tmux commands and is often remapped to a more comfortable key such as Ctrl+a. After detaching, you can drop the connection, close the laptop, switch WiFi networks, without the session taking any damage. On the next login, tmux attach -t name is enough to continue exactly where you left off, including terminal history and running processes.
# Create a new named tmux session for a deployment task
tmux new -s deploy
# Inside the session: start a long-running process
./run-migration.sh --env=production
# Detach without killing the session: Ctrl+b, then d
# (connection can now drop safely, the process keeps running)
# List all active sessions from a fresh SSH login
tmux ls
# deploy: 1 windows (created Thu Jul 30 09:12:03 2026)
# Re-attach to the exact session by name
tmux attach -t deploy
# Attach to the only existing session without knowing its name
tmux attach
# Kill a finished session cleanly instead of just detaching
tmux kill-session -t deploy
A common beginner mistake is accidentally ending a session with exit or Ctrl+d instead of detaching it with the prefix. The difference is crucial: exit ends the shell and thus the session permanently, while detaching keeps the session alive. Anyone who cannot remember this should build an extra safety net into the tmux configuration, for example a confirmation prompt before closing the last window.
4. Windows and panes: the screen as a workspace
Inside a tmux session you can create any number of windows, each comparable to a browser tab. Ctrl+b c creates a new window, Ctrl+b n and Ctrl+b p switch to the next or previous window. For situations with many parallel windows, Ctrl+b w helps by showing an interactive list of all open windows that you can select directly instead of clicking through them one by one.
Even more important for daily work is splitting a window into several panes. Ctrl+b % splits the current pane vertically, Ctrl+b " splits it horizontally. This lets you fit, for example, an editor on the left, a live log on the top right and a free shell for commands on the bottom right, all visible at the same time without switching windows. Navigating between panes uses Ctrl+b followed by an arrow key, and zooming a single pane to full screen uses Ctrl+b z.
For recurring layouts, for example always the same three pane arrangement for server monitoring, the synchronize panes feature is worth using: with Ctrl+b : and the command setw synchronize-panes on, keyboard input is sent to all panes of a window simultaneously. This is especially handy when the same action, for example a package update, needs to run on multiple servers in parallel, each in its own SSH pane.
5. Configuration: tuning tmux.conf for daily use
The default key bindings of tmux are functional but not optimal for daily use. The configuration file ~/.tmux.conf lets you adapt the prefix key, colors, status bar and shortcuts to your own habits. One of the first sensible changes is remapping the prefix from Ctrl+b to Ctrl+a, because the latter sits closer to the home row and historically comes from GNU Screen, which makes the switch easier for former Screen users.
Another important point is mouse support: with set -g mouse on, panes can be selected by click, resized by dragging, and scrolled through the terminal history with the mouse wheel, which makes the transition noticeably easier especially for beginners. Visual orientation is helped by a customized status bar that shows session name, time and hostname, so it is clear at a glance which server you are currently on, a detail that quickly becomes important once you run parallel sessions across multiple servers.
# ~/.tmux.conf - practical defaults for daily server work
# Remap prefix from Ctrl+b to Ctrl+a (closer to home row, Screen-compatible)
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Enable mouse support: click panes, drag borders, scroll history
set -g mouse on
# Start window and pane numbering at 1 (0 is awkward to reach)
set -g base-index 1
setw -g pane-base-index 1
# Increase scrollback buffer for long log sessions
set -g history-limit 50000
# Faster key repetition, no annoying delay after prefix
set -sg escape-time 0
# Status bar: show session name, hostname and time at a glance
set -g status-style bg=colour234,fg=colour137
set -g status-left "#[fg=colour46]#S "
set -g status-right "#[fg=colour214]#H #[fg=colour255]%H:%M"
# Split panes using current directory
bind '"' split-window -v -c "#{pane_current_path}"
bind '%' split-window -h -c "#{pane_current_path}"
# Reload config without restarting tmux
bind r source-file ~/.tmux.conf \; display "Config reloaded"
6. Automating and scripting session setups
Anyone who needs the same environment on a server every day, for example one window for logs, one for the editor and one for git status, should not build that structure manually every single time. tmux offers the combination of new-session, split-window and send-keys for exactly this, which can be assembled into a complete automation inside a shell script. Such a script builds the entire session including windows, panes and already running commands when executed, with no manual clicking involved.
For more complex requirements, especially when several projects each need their own session structure, the tool tmuxinator has established itself in practice, translating YAML configuration files into complete tmux layouts. For most cases, however, a simple Bash script is entirely sufficient and has the advantage of working directly on any server with tmux installed, without an extra dependency.
#!/usr/bin/env bash
# tmux-dev-session.sh - build a standard three-pane dev layout automatically
set -euo pipefail
SESSION="webproject"
# Only create the session if it does not already exist
if ! tmux has-session -t "$SESSION" 2>/dev/null; then
tmux new-session -d -s "$SESSION" -n "editor" -c "/var/www/webproject"
# Split into a log pane on the right
tmux split-window -h -t "$SESSION:editor" -c "/var/www/webproject"
tmux send-keys -t "$SESSION:editor.1" "tail -f var/log/exception.log" C-m
# Split the log pane again for a free shell below it
tmux split-window -v -t "$SESSION:editor.1" -c "/var/www/webproject"
tmux send-keys -t "$SESSION:editor.2" "git status" C-m
# Select the first pane (editor) before attaching
tmux select-pane -t "$SESSION:editor.0"
fi
tmux attach -t "$SESSION"
7. GNU Screen in practice: when tmux is not available
Despite the advantages of tmux, there are environments where Screen remains the more pragmatic choice, for example on minimal container images, old embedded systems, or servers without root rights to install additional packages. Screen has been part of the standard installation on many distributions for decades and is therefore often immediately available without even having to touch a package manager.
The basic commands of Screen and tmux are conceptually similar but differ in key bindings. A new session starts with screen -S name, detaching happens with Ctrl+a followed by d, and reattaching with screen -r name. A special case in practice is a hanging session still marked as attached even though the corresponding connection was closed long ago, for example after a hard connection drop. Here screen -d -r name helps, forcibly detaching the session from the old connection and reattaching it in the current terminal.
Important for practical use is that Screen, unlike tmux, does not come with native, comfortable pane management. Splits have been possible since version 4, but feel considerably more cumbersome. Anyone who regularly wants to work with split views should switch to tmux wherever possible and use Screen only where no other option exists.
8. Common pitfalls in daily server work
Probably the most common pitfall is forgetting session names. Anyone who regularly runs several tmux sessions in parallel, for example one per project or client, quickly loses track once all sessions carry the default name. The solution is simple: give every session a descriptive name from the start, for example the project name or a short hostname, so that tmux ls reveals at a glance which session is responsible for what.
A second pitfall concerns environment variables. A tmux session keeps the environment that was active when the session started, even when you later log in again via SSH with different environment variables. This can lead to confusing effects, for example when SSH agent forwarding no longer works in an old session because the stored SSH_AUTH_SOCK variable points to a long closed socket. The robust solution is a small update script that refreshes the relevant variables on every new attach instead of relying on the original environment.
Third, many underestimate the importance of the scrollback buffer. If history-limit is set too low, old log output disappears after a short time even though the session itself is still running. For debugging sessions with a lot of output, a much higher value than the default is recommended, combined with the ability to switch into copy mode with Ctrl+b [ and search specifically for earlier output.
9. tmux versus Screen compared directly
For the decision between the two tools, a direct, practice oriented comparison of the most important properties that actually matter in daily server work is worthwhile.
| Property | tmux | GNU Screen |
|---|---|---|
| Pane management | Native, intuitive, well documented | Available, but more cumbersome |
| Configuration | Clearly structured tmux.conf | screenrc, older syntax |
| Availability | Often needs to be installed | Preinstalled almost everywhere |
| Plugin ecosystem | Active (TPM, Resurrect, Continuum) | Barely developed further |
| Scripting/API | Extensive send-keys/commands | More limited command set |
Overall, tmux is the right choice for most new setups today, precisely because of native pane management and active development. Screen remains relevant as a fallback for systems where no additional software can or should be installed, and as a tool that is immediately available on virtually any Unix system in an emergency situation.
Mironsoft
Linux server administration and remote work setups
Server access that survives every connection drop?
We set up robust tmux workflows for teams, including session automation, secure SSH configuration and server hardening, so remote work stays productive and resilient.
Session setup
Individual tmux configuration and automation scripts for teams
Remote workflow
SSH access, multiplexer and server configuration from a single source
Server hardening
Secure access chains for productive Linux environments
10. Summary
A terminal multiplexer such as tmux is the practical answer to a structural problem of remote work: SSH connections drop, and without decoupled sessions, running processes are lost with them. With sessions, windows and panes, tmux offers not only resilience but also a more efficient workspace where several tasks remain visible simultaneously, without constantly switching between SSH connections.
A customized tmux.conf with mouse support, a larger scrollback buffer and a clear status bar makes daily handling noticeably more pleasant, while automation scripts build recurring session layouts in seconds. GNU Screen remains important as a fallback when tmux is not available, but should no longer be the first choice for new setups. Once these tools are integrated into the daily workflow, you will not want to work without them again.
tmux and Screen in Daily Use, the Essentials at a Glance
Persistence
tmux new -s name starts a session that easily survives an SSH disconnect.
Detach/Attach
Ctrl+b d detaches safely, tmux attach -t name reattaches reliably.
Panes and windows
Split views for editor, logs and shell simultaneously, without switching windows.
Automation
Scripts with new-session, split-window and send-keys build layouts in seconds.