What tmux does
Your SSH connection drops halfway through an `apt upgrade`, and your entire deploy stalls because your terminal is dead. If you had used tmux, that upgrade would have kept running. This article explains what tmux does, how to set it up, and why it changes your workflow — for those who work on Linux servers or in a terminal with editors like Vim or Emacs.
Requirements
- A Linux system (Debian/Ubuntu, RHEL/Fedora, or another distro) or macOS
- tmux version 3.7c or newer (check with `tmux -V`)
- Basic knowledge of the command line
- An SSH connection to a server, or a local terminal
What tmux does
Tmux is a terminal multiplexer: it lets you run multiple terminal sessions within one screen. The name is an abbreviation of terminal multiplexer — it multiplies the functionality of a single terminal window by supporting sessions, windows, and panes within one interface.The core functionality is simple: you start a session, you do your work, and you can detach that session from your screen. The session keeps running in the background. Later you re-attach it, wherever you are. Your processes don't stop when your laptop closes or your wifi drops.
That makes tmux indispensable for long-running tasks: builds, scripts, server processes, database migrations. Self-hosting sounds great, until something crashes on Sunday night at 11:30 PM. Then you're not a customer waiting on the helpdesk. Then you are the helpdesk — and then you want your session to still be alive.
Installation
Chances are tmux is already installed. Check it first:tmux -V
If nothing shows up, install it via your package manager:
<h2>Debian/Ubuntu</h2>
sudo apt install tmux
<h2>RHEL/Fedora</h2>
sudo dnf install tmux
<h2>macOS (via Homebrew)</h2>
brew install tmux
Basics: your first session
Start a new session:tmux new -s werk
You're now in a tmux session, but you barely notice it — except for the status bar at the bottom. It shows your session name, windows, and the time.
The most important concept is the prefix key: by default `Ctrl+b`. Everything you want to do in tmux starts with that combination. Then you press a second key for the action.
The three most important commands to remember:
| Action | Keys | |-------|---------| | Detach (disconnect session) | `Ctrl+b` then `d` | | New window | `Ctrl+b` then `c` | | Next window | `Ctrl+b` then `n` |
Detach is the most important. Press `Ctrl+b`, release, press `d`. You're back in your normal shell, and your session keeps running.
To re-attach:
tmux attach -t werk
If your SSH connection drops, you only need to log in again and run the above command. Everything is still there exactly as you left it.
Windows and panes
Within one session you can have multiple windows — think of tabs in a browser. And within one window you can split the screen into panes, so you see two or more terminals at once.| Action | Keys | |-------|---------| | Split vertically (left/right) | `Ctrl+b` then `%` | | Split horizontally (top/bottom) | `Ctrl+b` then `"` | | Switch between panes | `Ctrl+b` then arrow key | | Close pane | Type `exit`, or `Ctrl+d` |
This is where tmux proves its value for editor users. You open Vim in one pane, a shell in the pane below, and a `tail -f` on a log file in the right pane. You no longer need to alt-tab between terminal windows.
A practical setup:
1. Start a session: `tmux new -s dev` 2. Split horizontally: `Ctrl+b` then `"` 3. Open Vim in the top pane: `vim` 4. Go to the bottom pane: `Ctrl+b` then down arrow 5. Run your build or tests there
You see immediately what happens when your code compiles or tests run, without switching windows.
Detach keeps running
Tmux's client-server model is what makes the difference. When you start tmux, a server process runs that manages your sessions. Your terminal is just a client connecting to it. If you disconnect — deliberately or due to a network outage — the server keeps running.Test it yourself:
1. Start a session: `tmux new -s test` 2. Start a long-running command, for example: `ping 8.8.8.8` 3. Detach with `Ctrl+b` then `d` 4. Close your terminal completely 5. Open a new terminal and type: `tmux attach -t test`
The ping is still running. That's the whole point.
Configuration: your own tmux
By default, tmux uses emacs-style key combinations. If you work with Vim, you can adjust that. Tmux checks your `EDITOR` environment variable at startup: if it contains 'vi', tmux automatically switches to vi-style key bindings in copy-mode.For further adjustments, create a configuration file:
touch ~/.tmux.conf
A basic setup that is widely used:
<h2>Change the prefix key to Ctrl+a (like GNU Screen)</h2>
set -g prefix C-a
unbind C-b
bind C-a send-prefix
<h2>Enable mouse support</h2>
set -g mouse on
<h2>Increase the scrollback buffer</h2>
set -g history-limit 50000The mouse option is controversial: some users swear by it, others find it annoying when selecting text in the terminal. Turn it on, try it for a week, and turn it off if it bothers you. It costs nothing to change.
After a change, reload the configuration:
tmux source-file ~/.tmux.conf
Scriptability
Tmux can not only be operated interactively, but also from scripts. This makes it possible to set up complex development environments with a single command.An example: a session with three windows for a project.
#!/bin/bash
tmux new-session -d -s project -n editor
tmux send-keys -t project 'vim src/index.js' C-m
tmux new-window -t project -n shell
tmux send-keys -t project 'git status' C-m
tmux new-window -t project -n logs
tmux send-keys -t project 'tail -f /var/log/app.log' C-m
tmux select-window -t project:editor
tmux attach -t projectThis script starts a session named `project`, opens Vim in the first window, a shell with `git status` in the second, and a log viewer in the third. Then it attaches you to it.
There are also tools that manage these kinds of setups — `tmuxinator` and `tmuxp` are the best known. They work with YAML configurations and are handy if you have many different project environments. For one or two projects, a simple script is enough; those tools mainly add structure when you have dozens of them.
Common mistakes
Forgetting that you are in tmux. You run commands, and suddenly a shortcut no longer works. Check the status bar at the bottom. If there is a session name, you are in tmux. Press `Ctrl+b` and then `d` to detach, or stay and learn the prefix.`Ctrl+b` does not work in GNU Screen. Tmux and GNU Screen are different programs with different prefix keys. Screen uses `Ctrl+a` by default. If you are used to Screen, adjust your tmux config as described above.
Scrollback does not work. In tmux you do not scroll with your mouse wheel unless you enable mouse support. Without that option, you use `Ctrl+b` and then `[` to enter copy-mode, after which you browse the buffer with arrow keys or Page Up/Page Down. With mouse support enabled, scrolling works as you expect.
Session lost after reboot. Tmux sessions do not survive a system restart — they run on the server, not in your terminal, but in the memory of that server. For processes that need to survive a reboot, you need a service manager such as systemd. Tmux is for surviving connection interruptions, not power outages.
Verification
Check whether your installation works and you manage sessions:<h2>Show all active sessions</h2>
tmux list-sessions
<h2>Show tmux version</h2>
tmux -V
<h2>Show all active processes named tmux-server</h2>
ps aux | grep tmuxIf you see a session in `list-sessions`, your tmux server is running correctly. Attach to one with `tmux attach -t Frequently asked problems
`tmux attach` gives "no sessions"
You have no active sessions. Start one with `tmux new -s work`, or check with `tmux list-sessions` whether you have the session name right.
Colors look different in tmux Tmux supports 256 colors, but your terminal must also do so. Start tmux with `tmux -2` to activate 256-color support, or set `set -g default-terminal "screen-256color"` in your `.tmux.conf`.
`tmux source-file` gives errors about unknown options Your configuration contains options that your tmux version does not know. Check your version with `tmux -V` and compare with the documentation for that version. Options change between versions; a config written for 3.7 does not always work on 3.2.
Tmux is not a graphical tool, and that is precisely its strength. Everything runs on text and key combinations, which makes it lightweight — but also gives a learning curve. The first few days you will press `Ctrl+b` and forget which key comes after it. After a week it is in your muscles, and you will wonder how you ever worked without it. And when you do find yourself without it — on a system where tmux is not installed — you really discover what you are missing: the peace of a session that keeps running, independent of your connection.