Introduction
You SSH into a server, start a long task, and then your Wi-Fi blinks. The connection drops, the terminal dies, and so does everything running inside it. Anyone who has managed a server has lost work this way at least once. tmux is the tool that makes it stop happening.
The Problem tmux Solves
A plain terminal window has some real limits:
- It's tied to your connection. Close the window or lose the network, and the programs inside it are killed.
- It's one screen. Watching logs while editing a file means juggling multiple windows or SSH sessions.
- It forgets. When you come back tomorrow, your working setup is gone and you rebuild it from scratch.
On a laptop, that's an annoyance. On a remote server, where you may be running migrations, builds, or a log tail, it's a risk.
The tmux Approach
tmux (short for terminal multiplexer) runs a server process on the machine that holds your terminal sessions. Your screen is just a window onto them. You can disconnect, close your laptop, or lose your network, and the sessions keep running. Later you reconnect and pick up exactly where you left off.
Core idea: Your terminal sessions should live on the machine doing the work, not on the connection you happen to be using right now.
Three Terms to Know
- Session โ A collection of windows that you can detach from and reattach to. Usually one per project.
- Window โ Like a tab inside a session.
- Pane โ A split inside a window, so you can see several terminals at once.
Simple Example
# Start a named session
tmux new -s blog
# ...run something long, then detach with Ctrl-b followed by d
# Later, even from a new SSH connection:
tmux attach -t blog
Everything you started is still running, as if you had never left.
How tmux Fits a Server Workflow
On a VPS, tmux becomes part of your daily routine.
Keep Long Jobs Alive
Start a session before a database migration, a big file transfer, or a build. If your connection drops halfway through, the job doesn't notice.
Watch Several Things at Once
A typical layout for a Django server:
- One pane tailing the application logs with
journalctl -u blog -f - One pane running
htopto watch CPU and memory - One pane as a free shell for commands
Split panes with the keyboard and you have a small dashboard in a single terminal.
Pick Up Where You Left Off
Name your sessions after projects (tmux new -s blog, tmux new -s infra). Running tmux ls shows what's alive, and tmux attach -t blog drops you straight back in.
Why This Matters
-
Resilience โ Dropped connections stop being emergencies.
-
Persistent workspaces โ Your layout, running programs, and scrollback survive between sessions.
-
One terminal, many tasks โ Windows and panes replace a pile of terminal tabs.
-
Lightweight and everywhere โ tmux is tiny, runs over any SSH connection, and is available in the Debian package repositories.
Key tmux Commands
By default, every tmux shortcut starts with the prefix, Ctrl-b. Press it, release it, then press the next key.
| Shortcut | Purpose |
|---|---|
Ctrl-b d |
Detach from the session (it keeps running) |
Ctrl-b c |
Create a new window |
Ctrl-b n / Ctrl-b p |
Next / previous window |
Ctrl-b % |
Split the pane left and right |
Ctrl-b " |
Split the pane top and bottom |
Ctrl-b + arrow keys |
Move between panes |
Ctrl-b z |
Zoom a pane to full screen, and back |
Ctrl-b , |
Rename the current window |
Ctrl-b [ |
Scroll back and copy text (press q to leave) |
Outside a session, the commands you'll use most are tmux new -s name, tmux ls, and tmux attach -t name.
A Small, Useful Config
tmux reads ~/.tmux.conf when it starts. A few lines go a long way:
# Use the mouse for scrolling and selecting panes
set -g mouse on
# Start numbering at 1, which matches the keyboard
set -g base-index 1
setw -g pane-base-index 1
# Keep more scrollback
set -g history-limit 10000
# Reload the config with Ctrl-b r
bind r source-file ~/.tmux.conf \; display-message "Config reloaded"
Edit the file, press Ctrl-b r, and the changes apply without restarting anything.
Getting Started
-
Install it:
bash sudo apt install tmux -
Start a session with
tmux new -s practice. -
Split a pane, move between panes, then detach with
Ctrl-b d. -
Reattach with
tmux attach -t practiceand notice that everything is still there. -
Add a few lines to
~/.tmux.confonly when something annoys you. Resist the urge to copy a giant config.
Know the Limits
- The prefix takes getting used to. Expect a week of reaching for shortcuts that don't exist yet.
- Scrolling and copying work differently from a normal terminal until you learn copy mode, or enable the mouse.
- Sessions don't survive a reboot. tmux keeps your work alive across disconnects, not across a restart of the machine.
The Philosophy
tmux isn't about being clever in the terminal. It's about separating your work from your connection. Once that clicks, flaky Wi-Fi, closed laptops, and forgotten terminal tabs stop mattering.
Learn four shortcuts first: new session, detach, attach, split. Everything else can wait until you need it.
This post is part of a series on the tools behind this blog: Django, HTMX, Tailwind CSS, PostgreSQL, SQLite, Docker, Debian on a VPS, and now tmux. Posts are authored in the Django admin as Markdown and rendered to HTML on save.