screen vs tmux: Which Terminal Multiplexer

screen vs tmux: Which Terminal Multiplexer

A terminal multiplexer runs terminal sessions that outlive your connection to them.

The problem it solves is concrete: you SSH into a server, start a four-hour database migration, your laptop sleeps, the connection drops, and the migration dies partway through with no record of where it got to.

Run it inside tmux and the connection dropping is irrelevant. The process belongs to tmux, tmux is still running on the server, and you reattach when you reconnect.

ssh server
tmux new -s migration
# start the long thing
# connection drops, or you press Ctrl+b d
# later:
ssh server
tmux attach -t migration

That alone justifies learning one.

tmux

sudo apt install tmux
tmux                          # new unnamed session
tmux new -s work              # new named session
tmux ls                       # list sessions
tmux attach -t work           # reattach
tmux kill-session -t work

The prefix is Ctrl+b. Every command starts with it: press the prefix, release, then press the command key.

Ctrl+b d      detach
Ctrl+b c      new window
Ctrl+b n / p  next / previous window
Ctrl+b 0-9    go to window by number
Ctrl+b ,      rename window
Ctrl+b w      list windows

Ctrl+b %      split vertically
Ctrl+b "      split horizontally
Ctrl+b o      next pane
Ctrl+b arrow  move between panes
Ctrl+b z      zoom the current pane to full screen
Ctrl+b x      close pane

Ctrl+b [      scroll mode, q to exit
Ctrl+b ?      list every binding

Ctrl+b z is the one people discover late and then use constantly. It expands the current pane to fill the window and toggles back, which is how you read output in a pane that is too small without disturbing your layout.

Ctrl+b [ enters copy mode, which is how you scroll back. Without it the mouse wheel does nothing useful, because the terminal’s scrollback and tmux’s are different things.

Configuration worth having

# ~/.tmux.conf

# Ctrl+a, from screen muscle memory
unbind C-b
set -g prefix C-a
bind C-a send-prefix

set -g mouse on
set -g history-limit 50000
set -g base-index 1
setw -g pane-base-index 1

# splits that keep the current directory
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

# vi keys in copy mode
setw -g mode-keys vi

# reload config
bind r source-file ~/.tmux.conf \; display "reloaded"

# do not wait after Escape, which delays vim
set -sg escape-time 10
tmux source-file ~/.tmux.conf

Four of these matter more than the rest.

set -g mouse on enables clicking between panes, dragging to resize, and wheel scrolling. Note that with mouse mode on, selecting text to copy requires holding Shift in most terminals, because tmux is now intercepting mouse events.

base-index 1 makes windows start at 1 rather than 0, which matches the number keys’ physical order.

escape-time 10 fixes a real annoyance: the default 500ms delay after Escape makes vim feel sluggish inside tmux.

-c "#{pane_current_path}" makes new splits open in the same directory, which the default does not.

screen

screen                        # new session
screen -S work                # named
screen -ls                    # list
screen -r work                # reattach
screen -x work                # attach without detaching others
screen -d -r work             # detach elsewhere, attach here

The prefix is Ctrl+a.

Ctrl+a d      detach
Ctrl+a c      new window
Ctrl+a n / p  next / previous
Ctrl+a "      list windows
Ctrl+a A      rename
Ctrl+a S      split horizontally
Ctrl+a |      split vertically
Ctrl+a Tab    next region
Ctrl+a [      scroll mode
Ctrl+a ?      help

Note the split behaviour: in screen, splitting creates an empty region and you must then press Ctrl+a Tab to move into it and Ctrl+a c to start a shell there. tmux splits and gives you a shell immediately.

# ~/.screenrc
startup_message off
defscrollback 20000
hardstatus alwayslastline
hardstatus string '%{= kG}[%{G}%H%{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]%{=b C}[ %m/%d %c ]%{W}'

startup_message off removes the licence screen on every start, which is the first thing everyone turns off.

The comparison

screentmux
Default prefixCtrl+aCtrl+b
SplittingCreates empty regionCreates a shell
ConfigurationCrypticReadable
ScriptingLimitedExtensive
MousePoorGood
Session sharingscreen -xtmux attach
DevelopmentMinimalActive
Preinstalled onMore systemsFewer

Use tmux for anything new. Better pane handling, a configuration format a person can read, proper scripting, and ongoing development.

Know enough screen to reattach a session, because it is preinstalled on more systems than tmux, particularly older RHEL and enterprise machines where you may not be allowed to install anything.

The minimum screen survival kit:

screen -ls        # what is running
screen -r         # reattach
Ctrl+a d          # detach

Scripting a layout

tmux can build a working environment in one command:

#!/usr/bin/env bash
SESSION=dev

tmux new-session -d -s $SESSION -n editor
tmux send-keys -t $SESSION:editor 'cd ~/project && vim' C-m

tmux new-window -t $SESSION -n server
tmux send-keys -t $SESSION:server 'cd ~/project && npm run dev' C-m

tmux new-window -t $SESSION -n logs
tmux split-window -t $SESSION:logs -h
tmux send-keys -t $SESSION:logs.0 'journalctl -f -u myapp' C-m
tmux send-keys -t $SESSION:logs.1 'htop' C-m

tmux select-window -t $SESSION:editor
tmux attach -t $SESSION

One command, three windows, everything running. tmuxinator and tmuxp do this declaratively from YAML if you want more than a shell script.

Persistence

tmux sessions do not survive a reboot. Two plugins address this:

# ~/.tmux.conf, with tpm installed
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-restore 'on'

resurrect saves and restores layouts and working directories with prefix + Ctrl+s and prefix + Ctrl+r. continuum automates it.

They restore the layout, not the running processes. A migration that was in progress is gone.

Alongside the alternatives

mosh solves a different problem: it survives IP changes and network interruptions and gives responsive typing over high-latency links. It does not give you windows or panes, and it does not keep processes alive after you disconnect entirely. mosh plus tmux is a genuinely good combination for a laptop that moves between networks.

Zellij is a newer multiplexer with discoverable keybindings shown on screen, which addresses the main objection to both tools here. Worth a look if the learning curve is the obstacle.

A systemd service is the right answer for anything that should run permanently. A multiplexer is for interactive work you want to come back to, not for daemonising something. Our systemd service guide covers doing that properly.

nohup or setsid detaches a single command and gives you no way to interact with it afterwards. Our job control guide covers those.

For the specific case of “I am about to run something long on a server I am connected to over SSH”, a multiplexer is the correct tool, and forming the habit of typing tmux before you start is worth more than any of its other features.

Frequently Asked Questions

Why use a terminal multiplexer at all?

Processes started inside one survive your connection dropping, because they belong to the multiplexer rather than to your SSH session. Running a long upgrade or migration inside tmux means a lost connection is an inconvenience rather than a half-finished operation you cannot see the state of.

Should I learn screen or tmux?

tmux for anything new. It has better window and pane handling, a readable configuration format, and active development. screen is worth knowing because it is preinstalled on more systems, particularly older enterprise ones where you may not be permitted to install anything.

What is the prefix key?

A key combination that tells the multiplexer the next keystroke is a command rather than input for the program inside. screen uses Ctrl+a and tmux uses Ctrl+b by default, and many tmux users rebind it to Ctrl+a out of habit from screen.

How do I reattach to a session I left running?

Run tmux attach, or tmux attach -t followed by the session name if there are several. For screen the equivalent is screen -r, or screen -x to attach without detaching anyone else who is already connected.

Why does my mouse not work in tmux?

Mouse support is disabled by default. Add set -g mouse on to your tmux configuration to enable clicking between panes, resizing by dragging, and scrolling with the wheel. Note that with mouse mode on, selecting text for copy requires holding Shift in most terminals.

Can two people share one session?

Yes, and both tools support it. tmux attach without the -d flag lets another user join an existing session, and screen -x does the same. Both see the same screen and can type, which is genuinely useful for pair debugging on a remote server.