You’re three commands into a deploy over ssh when the Wi-Fi drops, and the shell dies with it. Or you juggle six terminal tabs and lose track of which one runs the dev server. tmux fixes both: it keeps your shells running on their own, lets you split one terminal into many, and lets you walk away and come back to exactly where you left off.

This guide covers the 20% of tmux that does 80% of the work: sessions, windows, panes, the prefix key, and a small configuration file. A searchable command reference and a curated set of videos, podcasts, books, and online resources close the article.

What You’ll Learn

  • When tmux is the right tool, and when a terminal app’s tabs are enough.
  • How sessions, windows, and panes fit together.
  • How the prefix key works, so every binding in the reference makes sense.
  • How to configure tmux with a .tmux.conf file.
  • How to add plugins and keep remote work alive over ssh.

When to Use Tmux

tmux is a terminal multiplexer. It runs a server in the background that owns your shells, and your terminal window is only a client looking at them. Close the window, lose the network, or log out, and the shells keep running until you reattach.

What Tmux Does Well

  • Keeping long-running work alive on a remote server when your ssh connection drops.
  • Splitting one terminal into panes, so an editor, a test runner, and logs sit side by side.
  • Grouping each project into its own session that you can switch between in a keystroke.
  • Scripting a repeatable workspace layout with a few lines of configuration.

Where Tmux Is Not the Right Tool

  • A single shell on your own laptop, where your terminal app’s tabs already do the job.
  • Graphical programs (tmux only multiplexes text terminals).
  • Long-running services that belong under a process supervisor such as systemd.

Install tmux with your package manager and check the version. Everything in this guide works on tmux 3.x.

# macOS
brew install tmux

# Debian or Ubuntu
sudo apt install tmux

tmux -V

Sessions, Windows, and Panes

tmux organizes your terminals in three levels. Learn these three words and the rest of tmux follows.

  • A session is a named workspace, usually one per project. It survives when you detach.
  • A window is a full-screen tab inside a session. The status bar at the bottom lists them.
  • A pane is a rectangle inside a window. Split a window into as many panes as fit on screen.
graph TB S["tmux server
(runs in the background)"] S --> A["Session: blog"] S --> B["Session: api"] A --> W1["Window 0: editor"] A --> W2["Window 1: server"] W1 --> P1["Pane: nvim"] W1 --> P2["Pane: tests"] W2 --> P3["Pane: hugo server"]

Start a named session, detach from it, and reattach:

tmux new -s blog        # start a session named blog
# ...press Ctrl-b, then d, to detach...
tmux ls                 # list sessions: blog is still running
tmux attach -t blog     # reattach to it

If tmux ls or tmux attach answers no server running on /tmp/tmux-501/default (or a similar path), no tmux server is running yet. Nothing is broken. Start a session with tmux new -s name, and the server starts with it.

To jump between sessions without leaving tmux, press Ctrl-b s and pick one from the list, or run tmux switch -t name from a shell inside tmux. Outside tmux, switch has no client to move, so use tmux attach -t name instead.

The Prefix Key

Every tmux key binding starts with the prefix key, Ctrl-b by default. Press and release Ctrl-b, then press the command key. The reference below writes this as prefix X, so prefix c means press Ctrl-b, let go, then press c.

The prefix keeps tmux out of the way of the programs you run inside it. Without it, tmux would steal keys from your shell and your editor.

The bindings you’ll use every day:

  • prefix c creates a window, and prefix n and prefix p move to the next and previous one.
  • prefix % splits the current pane left and right, side by side.
  • prefix " splits the current pane top and bottom, one above the other.
  • prefix followed by an arrow key moves to the pane in that direction.
  • prefix d detaches, leaving everything running.
  • prefix ? lists every binding, when you forget one.

The two split keys trip up almost everyone, because the underlying command names them after the divider: prefix % runs split-window -h, which draws a vertical line between the new panes. Remember the keys by the result, not the flag.

Configure Tmux

tmux reads its configuration from ~/.tmux.conf when the server starts. tmux 3.1 and later also look for ~/.config/tmux/tmux.conf. Each line is a tmux command, the same commands you can type at the prefix : prompt.

A small starting configuration:

# Use Ctrl-a as the prefix instead of Ctrl-b
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# Turn on the mouse: click panes, drag borders, scroll
set -g mouse on

# Number windows from 1, to match the keyboard
set -g base-index 1

# Reload this file with prefix r
bind r source-file ~/.tmux.conf \; display "Config reloaded"

Changes don’t apply to a running server until you reload. Run tmux source-file ~/.tmux.conf, or press prefix r once the binding above is in place.

The configuration file can also build your workspace. new-session -d creates a session in the background, and -c sets its starting directory:

# Create named sessions, each starting in its project directory
new-session -d -s blog -n main -c ~/Projects/blog
new-session -d -s api -n main -c ~/Projects/api

Then tmux attach -t blog drops you into a ready workspace. For a single session, tmux new -A -s blog attaches when the session exists and creates it when it doesn’t.

Practice Tmux

Practice beats reading for key bindings. The terminal below runs real tmux 3.7c in this page, in a session named practice. Nothing downloads until you press Start, nothing you type leaves your browser, and Reset brings back a fresh session. Click the terminal to type, and press Tab to leave it.

Practice the commands on this page in real tmux, right here. Nothing downloads until Start (about 4.5 MB).

reader@practice:~$






















[practice]0:sh*

The practice terminal needs JavaScript. Every command in the reference also works in tmux on your own machine.

Run this drill in the practice terminal or in your own. It takes about five minutes.

  1. Run tmux new -s practice to start a session. The practice terminal starts inside one already, so skip this step there.
  2. Press prefix % to split left and right, then prefix " to split the right pane top and bottom.
  3. Press prefix and an arrow key to move between the three panes, then prefix z to zoom one and prefix z again to restore it.
  4. Press prefix c to open a second window, and prefix , to name it.
  5. Press prefix d to detach, run tmux ls to see the session still running, then tmux attach -t practice to come back.
  6. Press prefix [ to enter copy mode, scroll up with the arrow keys, and press q to leave.
  7. Run tmux kill-session -t practice when you’re done.

Command Reference

Search the reference to find a binding fast. Each prefix entry means press Ctrl-b, release it, then press the key.

Session Commands

  • tmux - Start a new session with a numbered name
  • tmux new -s name - Start a new session called name
  • tmux new -A -s name - Attach to the session called name, or create it when it doesn’t exist
  • tmux ls - List all sessions
  • tmux attach -t name - Attach to the session called name from outside tmux
  • tmux switch -t name - Switch to the session called name; run it from inside tmux, because outside tmux there is no client to switch
  • tmux kill-session -t name - Close the session called name and every window in it
  • prefix d - Detach from the session and leave it running
  • prefix $ - Rename the current session
  • prefix s - Choose a session from an interactive list

Window Commands

  • prefix c - Create a new window
  • prefix n - Move to the next window
  • prefix p - Move to the previous window
  • prefix w - Choose a window from an interactive list
  • prefix , - Rename the current window
  • prefix & - Close the current window (tmux asks to confirm)
  • prefix 0-9 - Move to the window with that number

Pane Commands

  • prefix % - Split the current pane left and right, side by side
  • prefix “ - Split the current pane top and bottom, one above the other
  • prefix o - Move to the next pane
  • prefix arrow key - Move to the pane in the direction of the arrow
  • prefix q - Show pane numbers; press a number while they show to jump to that pane
  • prefix x - Close the current pane (tmux asks to confirm)
  • prefix z - Zoom the current pane to fill the window, or restore it

Copy Mode Commands

  • prefix [ - Enter copy mode to scroll back through output and select text; press q to leave
  • prefix ] - Paste the most recently copied text

Help and Command Prompt

  • prefix ? - List every key binding
  • prefix : - Open the tmux command prompt to run commands such as kill-session
  • prefix t - Show a large clock in the current pane

Plugins and Networking

tmux has no built-in plugin system. The Tmux Plugin Manager (TPM) fills the gap. Clone it once, list plugins in your configuration, and let TPM fetch them.

git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

Add the plugins to the end of ~/.tmux.conf, followed by the line that starts TPM:

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'

run '~/.tmux/plugins/tpm/tpm'

Reload the configuration, then press prefix I (capital i) to install the listed plugins. tmux-sensible sets defaults most people want, and tmux-resurrect saves and restores sessions across a reboot. Installing plugins downloads them from GitHub, so it needs a network connection.

tmux earns its keep over ssh. Run tmux on the remote machine, not your laptop, so the shells live on the server:

ssh deploy@example.com
tmux new -A -s work

When the connection drops, the session keeps running on the server. Reconnect with ssh and run tmux new -A -s work again to pick up where you left off. If ssh refuses your key, fix your ssh key permissions first.

If you run tmux locally and again on the server, the outer tmux catches the prefix. Press the prefix twice (Ctrl-b Ctrl-b) to send it through to the inner tmux, or give the two a different prefix.

Learn Tmux: Beyond the Basics

With sessions, windows, panes, and a configuration file in hand, these resources take you further. Start with a video, then keep a book or the wiki open while you customize.

Video

Audio and Podcasts

Books

Online


Related Articles by Category