A terminal that keeps running after you close it is the whole pitch of tmux, and it takes about twenty minutes to learn the part you need. This is the long version for beginners: sessions, windows, panes, scrolling, a small config file and a cheat sheet, with screenshots of the real thing.
- Time
- 21 min
- Steps
- 18
- Updated
- 2 Dec 2026
You will learn
- Your first session
- The one thing to remember: the prefix
- Windows: tabs inside the session
- Panes: splitting one window
- Which pane is which
What you get, and what you need
tmux gives you a terminal that stays alive when you close the window. You start a session, run things in it, disconnect, and come back an hour or a week later to find everything exactly where you left it. On top of that you can split one terminal into several panes and keep a handful of windows open, all in a single SSH connection.
You need a Linux or macOS terminal and about twenty minutes. I wrote this for someone who has never used tmux, so every shortcut is spelled out. The screenshots are from tmux 3.4 and 3.8 with the default keys, so what you see is what you get.
Install it with your package manager:
# Debian, Ubuntu
sudo apt install tmux
# macOS with Homebrew
brew install tmux
# check the version
tmux -V
This matters most when you SSH into a server: you start something long, then the laptop goes to sleep or the Wi-Fi drops. Without tmux that job dies with your connection. With tmux it keeps running and you just reattach. If you run a home server and reach it from elsewhere, that alone is reason enough.
Step 1 of 18: Your first session
A session is the big container. Start one and give it a name, because names beat numbers the moment you have two of them:
tmux new -s work
Your terminal clears and a green bar appears at the bottom. That is the status bar. On the left is the session name in square brackets, then the list of windows. Right now there is one, called 0:bash, and the star marks the one you are looking at. Type commands as you always do.
Now the trick that makes tmux worth learning. Press Ctrl-b, let go, then press d. You are back in your normal shell and tmux says it detached. The session is still running in the background. List your sessions and go back in:
tmux ls
tmux attach -t work
Check that it worked: tmux ls prints one line per session, something like work: 1 windows (created Wed Nov 18 21:23:00 2026). The word (attached) is added while you are connected to it from another terminal.
tmux a works as a short version and attaches to the most recent session. If you close the terminal window or lose the connection without detaching, nothing is lost either: the session simply stays detached until you attach again.
![Terminal output: tmux new -s work, then the message [detached (from session work)] after Ctrl-b d, and tmux ls listing the session work with 1 windows](https://brewedbits.dev/wp-content/uploads/2026/11/tmux-detach-ls.png)
The screenshot is the whole round trip. tmux new -s work starts the session, Ctrl-b d leaves it, and tmux answers with the detached message. tmux ls still lists work, which is how you know it survived. Type tmux attach -t work and you are back where you were.
When you are done with a session for good, type exit in its last window, or kill it from outside:
tmux kill-session -t work

Step 2 of 18: The one thing to remember: the prefix
Almost every tmux shortcut is two steps. First you press the prefix, which is Ctrl-b by default. You let go of both keys. Then you press the command key. In the rest of this guide I write that as Ctrl-b followed by the key, so Ctrl-b d means: hold Ctrl, tap b, release, tap d.
The most common beginner mistake is holding everything down at once. Ctrl-b, release, then the next key. If nothing happens, that is usually why.
If you forget a shortcut, Ctrl-b ? shows the full list of key bindings in a scrollable screen, and q closes it. That list is also the best documentation of what your own tmux can do, because it shows your changes too.
Step 3 of 18: Windows: tabs inside the session
A window is what you would call a tab in a browser. Each one fills the whole screen and runs its own shell. I would use them to separate jobs: one for the editor, one for Docker, one for logs.
Ctrl-b ccreates a new window.Ctrl-b ngoes to the next window,Ctrl-b pto the previous one.Ctrl-b 0toCtrl-b 9jumps straight to that window number.Ctrl-b ,renames the current window. Do it right away, becausebashthree times in a row tells you nothing.Ctrl-b &closes the window after asking for confirmation. Typingexitdoes the same without asking.
The status bar is your map. In the screenshot there are three windows called editor, docker and logs. The star marks the one I am in and the dash marks the one I was in before. Ctrl-b l toggles back to that previous window, which saves a lot of hopping around.
Check that it worked: after Ctrl-b c the status bar shows a new entry and the star moves to it. If you closed a window by accident, the others keep their numbers, so a gap such as 0 1 3 is normal. Set renumber-windows on in the config if the gap bothers you.

Step 4 of 18: Panes: splitting one window
Panes cut a single window into pieces, so you can watch a log on one side while you type on the other. The two split shortcuts are the part that trips people up, because the symbols describe the line, not the direction of the cut:
Ctrl-b %splits left and right (the dividing line is vertical).Ctrl-b "splits top and bottom (the dividing line is horizontal).
You can keep splitting. The screenshot shows one window cut into three panes: a big one on the left, and the right half split in two. The blue border marks the pane you are typing in.
Moving around and managing panes:
Ctrl-band an arrow key moves to the pane in that direction.Ctrl-b ocycles through them.Ctrl-b, then an arrow key while still holding Ctrl, resizes the active pane by one cell. With Alt it moves five cells at a time. Another way isCtrl-b :followed byresize-pane -R 10.Ctrl-b zzooms the active pane to the whole window. Press it again to bring the others back. AZappears in the status bar while a pane is zoomed.Ctrl-b Spacecycles through the preset layouts if your panes ended up looking messy.Ctrl-b xcloses the active pane after asking.
Check that it worked: tmux list-panes prints one line per pane in the current window with its size, for example 0: [47x22] ... (active). The word (active) is the pane you are in. Zoom is my favourite of these. A log full of long lines gets unreadable in a quarter of the screen, so zoom it, read, and un-zoom.

The big pane on the left gets the output because it has the room. Every line is one pane: its number, its size in columns by rows, how much history it holds, and an id with a percent sign. (active) marks the pane you are typing in. The on at the bottom is tmux show -gv mouse after the mouse line from the config below.

Step 5 of 18: Which pane is which
With three or four panes you lose track of where you are. Press Ctrl-b q and tmux draws a big number over every pane for a couple of seconds, with the size of the pane in the corner. While the numbers are on screen, press a digit and you jump straight to that pane.
The numbers also matter outside the shortcuts. Commands such as tmux send-keys -t work:1.2 'ls' Enter use them to say which pane should receive something: session work, window 1, pane 2. You do not need that today, but it explains why tmux starts counting at zero and why the base-index option in the config exists.
Panes can also be rearranged without closing anything. Ctrl-b Space flips through the preset layouts, and Ctrl-b ! turns a pane into a window of its own. Closing a pane never touches the others, they simply grow to fill the space.

Step 6 of 18: Scrolling and copying text
This one confuses almost everyone at first: the mouse wheel and your terminal’s scrollback do not work the way you are used to, because tmux draws its own screen. To look at older output you enter copy mode.
Ctrl-b [enters copy mode. A small yellow counter appears at the top right of the pane.- Scroll with the arrow keys,
PageUpandPageDown. - Press
/to search forward, thennfor the next match. - Press
qto leave copy mode.
To copy, the default (emacs-style) keys are: Ctrl-Space to start selecting, move the cursor, then Alt-w to copy. Ctrl-b ] pastes the text into the active pane. If you set mode-keys vi in the config below, you select with Space and copy with Enter. That buffer lives inside tmux and is not your system clipboard, which is why it surprises people.
The mouse option in the next section makes scrolling much friendlier, so you may rarely need to think about copy mode.

Step 7 of 18: A starter ~/.tmux.conf
tmux works fine out of the box. These few lines are the ones I would add on day one. Put them in ~/.tmux.conf:
# mouse: click a pane, drag a border, scroll with the wheel
set -g mouse on
# a much longer scrollback (the default is 2000 lines)
set -g history-limit 50000
# start counting windows and panes at 1, like the keyboard row
set -g base-index 1
setw -g pane-base-index 1
# vi keys in copy mode
set -g mode-keys vi
# easier split keys, and new panes open in the current folder
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# Ctrl-b r reloads this file
bind r source-file ~/.tmux.conf \; display-message "Reloaded"
These lines load without errors in tmux 3.4 and the bindings show up in Ctrl-b ?. Reload it in a running session with Ctrl-b : and source-file ~/.tmux.conf (the screenshot shows that prompt, which appears in the status bar line and runs on Enter), or with the r binding from the file itself once it is loaded. Settings like base-index only affect windows you create after the reload.
Check that it worked: tmux show -gv mouse prints on when the line was picked up. Then click on a pane, drag a border and scroll with the wheel, all of which do nothing without it.
Some people remap the prefix to Ctrl-a because it is easier to reach. It is a matter of taste, and it collides with the start-of-line shortcut in your shell, so I would leave it alone until you actually feel the pain. If you do want it:
set -g prefix C-a
unbind C-b
bind C-a send-prefix

Step 8 of 18: Tmux cheat sheet
Every shortcut starts with the prefix: press Ctrl-b, let go, then press the key. Keep this card open in a second window while the keys are new, or download it as a one-page PDF.
- d
- detach, the session keeps running
- s
- pick a session from a list
- w
- tree of every session and window
- $
- rename the session
- c
- new window
- ,
- rename it
- np
- next or previous
- 0–9
- jump to a window by number
- l
- back to the last window
- %
- split left and right
- "
- split top and bottom
- z
- zoom a pane, again to restore
- x
- close the pane
- Altarrow
- resize by five cells
- [
- copy mode, / searches
- ]
- paste
- ?
- list every key
- :
- type a tmux command
tmux new -s nametmux lstmux a -t nametmux kill-session -a -t nameStep 9 of 18: Reading the built-in key list
You do not have to trust my cheat sheet. Press Ctrl-b ? and tmux prints every key binding it knows, with a short description, in a screen you can scroll with the arrow keys and PageDown. Press q to leave. The screenshot is the top of that list in tmux 3.4.
The notation takes a minute to read. C-b is Ctrl-b, the prefix. M- stands for the Meta key, which is Alt on most keyboards, so M-Up is Alt plus the up arrow. C-b C-b means pressing Ctrl-b twice, which sends a real Ctrl-b to the program in the pane, useful when you are running tmux inside tmux.
One thing in the list trips people up: tmux names the two splits the other way around from how they look. It calls % ‘split window horizontally’ and " ‘split window vertically’, because it describes how the panes are laid out and not the line between them. When you read tmux documentation, trust the picture in your head more than the adjective. And when you have changed the config, the list shows your own bindings too, which makes it the quickest way to check that a bind line took effect.

Step 10 of 18: More than one session
One session per project is a good habit. A session called blog and one called server do not get in each other’s way, and each keeps its own windows and panes.
tmux new -s blogstarts a second session. Run it from a normal shell, not inside tmux.Ctrl-b sopens a list of all sessions and their windows. Move with the arrow keys and pressEnterto jump.Ctrl-b (andCtrl-b )switch to the previous and next session.Ctrl-b $renames the current session if you named it badly.
One command I would put in your fingers early is tmux new -As work. It attaches to the session called work when it exists and creates it when it does not. That means you can type the same line every time and never wonder which of the two you need.
tmux new -As work

Step 11 of 18: A typical day: SSH, a long job and a log
Here is how the pieces fit together on a server you reach over SSH, for example your home server over Tailscale. The commands are generic, so swap in your own host name.
ssh myserver
tmux new -As work
Inside the session, start the long job in the first window, say a big download or a backup script. Press Ctrl-b c for a second window and open the log there, or press Ctrl-b % to put the log in a pane next to the job. Check on both with Ctrl-b and an arrow key.

This is the day described above on one screen. The left pane runs the job, here a made-up backup script that copies imaginary photos. The right pane follows its log with tail -f backup.log. Both live in a window called backup, and a second window called notes waits in the status bar. Close the laptop and both keep going.
When the log gets long, zoom the pane with Ctrl-b z. It fills the whole window, and the Z in the status bar tells you that the other panes are only hidden. Press the same keys again and they come back, still running.
Now close the laptop. The SSH connection ends, but the job does not, because tmux runs on the server and not in your terminal. When you are back, connect again and run tmux new -As work. You land in the same windows, with the output that appeared while you were away.
The same works for a quick docker compose logs -f in one pane and your editor in another. I like this setup because it removes the fear of closing a window by accident. The shell you had in it was never in that window in the first place.

Step 12 of 18: A few extras once the basics stick
You do not need any of these on day one. They are the ones I would look at next, and every one is in the standard tmux, no plugin needed.
Ctrl-b !breaks the current pane out into its own window. Handy when a split got too cramped.Ctrl-b {andCtrl-b }swap the active pane with the previous or next one.Ctrl-b :and thensetw synchronize-panes onsends everything you type to every pane in the window at once. Useful for running the same command on several servers. Turn it off withsetw synchronize-panes off, and be careful, because it types into every pane, including the ones you forgot about.Ctrl-b tshows a big clock. It is not useful, but it is a nice way to check that tmux is responding.
The status bar is yours too. Colours and what it shows are all options, for example set -g status-style bg=green,fg=black, and the screenshots in this guide use a few such lines. It is optional, and I would skip it until you know what you want to see.
Step 13 of 18: Making the status bar yours
The green bar at the bottom is the part of tmux you look at all day, so it is worth a few lines. Everything on it is an option. The colours come from status-style, the left and right parts from status-left and status-right, and the highlighted window from window-status-current-style:
set -g status-style "bg=#313244,fg=#cdd6f4"
set -g status-left "[#S] "
set -g status-right "%H:%M %d-%b"
set -g window-status-current-style "bold,reverse"
#S expands to the session name, and the percent codes work like the ones in the date command, so %H:%M is the time as 21:38. The screenshots in this guide use the same idea with a green bar and a time on the right. Check the result by reloading the config and looking at the bar.

The same bar as before, now with the four lines above applied: a dark background, the session name in brackets on the left, the active window in reverse video, and the time and date on the right. The two commands in the window print the settings back. That is the quickest way to see what tmux really has, and it catches a typo in a colour code.
A word of caution from the other direction: a status bar crammed with CPU graphs, weather and battery is easy to build and annoying to keep working. I would start with the session name, the window list and a clock, and only add something when you catch yourself running a command just to see it.
Step 14 of 18: Habits that make it stick
- Give every session a name that says what it is for.
work,blogandserverbeat0,1and2a week later. - Start with
tmux new -As name, always. One command that works whether the session exists or not removes the decision. - Rename windows when you create them. The status bar is only a map if the labels say something.
- Detach with
Ctrl-b dinstead of closing the terminal. The result is the same for the session, but you decide when to leave. - Keep long-running things in a pane or window of their own, so you can zoom in on them with
Ctrl-b zand leave them alone the rest of the time.
None of these are tmux features. They are just how I would use it to avoid the usual mess. If you only take one, take the first.
Step 15 of 18: A ten-minute exercise
Reading shortcuts does not stick. Typing them does. Do this once, slowly, and most of the guide is in your fingers:
- Open a terminal and run
tmux new -s practice. - Press
Ctrl-b %to split the window in two, thenCtrl-b "to split the right half again. - Move between the three panes with
Ctrl-band an arrow key. Rundatein one andlsin another. - Press
Ctrl-b zto zoom a pane, thenCtrl-b zagain to bring the others back. - Press
Ctrl-b cto open a second window andCtrl-b ,to name itnotes. Switch back withCtrl-b p. - Run
seq 1 200, pressCtrl-b [, scroll up withPageUpand leave withq. - Press
Ctrl-b dto detach, runtmux lsand thentmux attach -t practice. Everything is where you left it. - Clean up with
tmux kill-session -t practice.
If step seven works, you have the part that matters. Everything else in tmux is a convenience on top of it.
Step 16 of 18: Questions beginners ask
- Can two people look at the same session? Yes. If both attach to the same session name, both see the same screen and both can type. It is a decent way to pair on a server, as long as you trust each other with the keyboard.
- Does it work with the mouse? With
set -g mouse onyou can click a pane, drag the borders and scroll. Selecting text to copy then happens inside tmux. Many terminals let you holdShiftwhile dragging to select with the terminal’s own selection instead, though that varies per terminal. - Does tmux keep running after a reboot? No. The sessions live in a background process, and that process ends when the machine restarts. Your long job survives a dropped connection, not a power cut.
- Does it slow anything down? Not in a way you will notice for normal shell work. It is a small program that sits between your terminal and your shells.
- Is it the same on a Mac? The shortcuts are identical. The only differences are the terminal app you use and where Homebrew puts the config tools, and the config file is still
~/.tmux.conf.
For anything else, man tmux is long, but it is the real reference, and the commands you type after Ctrl-b : are the same ones it describes.
Step 17 of 18: Where to go next
Part two of this series picks up where this guide stops: the advanced tmux guide covers a config that grows with you, vi copy mode, a useful status bar, formats and layouts. It assumes the sessions, windows, panes and small config from this guide.
Beyond that, once sessions, windows and panes are second nature, there are two directions. One is the plugin ecosystem: the tmux plugin manager (tpm) and plugins such as tmux-resurrect, which saves and restores sessions across a reboot. I have not covered them here because they are extras with their own install steps, and you should read their README before adding anything to your config.
The other is the manual. The tmux wiki has a Getting Started page that goes through the same ground as this guide from the maintainers’ point of view, and man tmux lists every command and option. Both are linked below.
For short, single-command lessons, I keep a growing list of tmux tips: one command or setting at a time, each with the line to copy.
Step 18 of 18: How it breaks
- Nothing happens when you press a shortcut: you probably held the keys together. Press Ctrl-b, release, then the second key.
sessions should be nested with care, unset $TMUX to force: you tried to start tmux inside tmux. Detach first, or press the prefix twice to send commands to the inner one.no sessionswhen you try to attach: the server was stopped, for example after a reboot. tmux does not bring sessions back after a restart on its own. Plugins such as tmux-resurrect exist for that, but they are an extra to look at later.can't find session: work: check the name withtmux ls. Names are case sensitive.

That one line is the whole error. tmux sees that $TMUX is set, which means you are already inside it, and refuses to start a second one by accident. Detach first, or run unset TMUX if you really do want a tmux inside tmux.
Twenty minutes of learning tmux pays back for years. I would start with just sessions and Ctrl-b d. Windows and panes follow once a dropped connection has killed a long job for you.
