How to Use tmux on a Linux VPS
Learn how to install and use tmux on your Linux VPS for persistent terminal sessions, split-pane workflows, and surviving SSH disconnects. Covers Debian 12 and Ubuntu 24.04.
You SSH into your VPS, start a long database migration, and your Wi-Fi drops. The process dies. Your work is gone.
tmux solves this. It runs your terminal sessions on the server itself, independent of your SSH connection. Disconnect, reconnect, and pick up exactly where you left off.
This tutorial covers tmux from first install to scripted multi-pane layouts. Every command runs on Debian 12 or Ubuntu 24.04.
What is tmux and why use it on a VPS?
tmux is a terminal multiplexer. It lets you run multiple terminal sessions inside a single SSH connection, and those sessions persist on the server even when you disconnect.
tmux organizes your work in three levels:
- Sessions are the top-level container. Each session is an independent workspace. You can detach from a session and reattach later.
- Windows live inside sessions. Think of them as tabs. Each window runs its own shell.
- Panes split a single window into multiple rectangles, each running its own command.
Session "deploy"
├── Window 0: "editor"
│ ├── Pane 0: vim
│ └── Pane 1: file watcher
└── Window 1: "logs"
└── Pane 0: journalctl -f
On a VPS, tmux gives you three things that matter:
- SSH disconnect protection. Your processes keep running when the connection drops. Reconnect and reattach.
- Multi-pane workflows. Monitor logs in one pane, run commands in another, edit files in a third. All inside one SSH connection.
- Session persistence. Leave a session running for days. Detach at the end of the day, reattach tomorrow.
How do I install tmux on Debian 12 and Ubuntu 24.04?
tmux is in the default repositories for both Debian 12 and Ubuntu 24.04. One command installs it.
sudo apt update && sudo apt install -y tmux
Verify the installation:
tmux -V
Expected output on Debian 12:
tmux 3.3a
Expected output on Ubuntu 24.04:
tmux 3.4
Sharp eyes: the version number confirms tmux installed from the official repositories. If you see nothing or "command not found," the install failed. Check apt output for errors.
How do I create and manage tmux sessions?
A tmux session is a persistent workspace that lives on the server. Start one, run your commands, and it stays alive even if you close your terminal.
Creating sessions
Start a new session with a name:
tmux new-session -s deploy
This creates a session called "deploy" and attaches you to it. You will see a green status bar at the bottom of your terminal. That status bar is tmux confirming you are inside a session.
To create a session without attaching to it (useful in scripts):
tmux new-session -d -s background
Verify it exists:
tmux list-sessions
background: 1 windows (created Thu Mar 19 10:00:00 2026)
How do I detach from a tmux session and reattach later?
This is the core VPS workflow. Detach from a session to free your terminal, then reattach later to resume your work. The session keeps running on the server.
To detach, press the prefix key followed by d:
Ctrl-b d
The prefix key is Ctrl-b by default. Press Ctrl and b together, release both, then press d. Every tmux keybinding works this way: prefix first, then the action key.
Your terminal returns to the regular shell. The session is still running.
To reattach:
tmux attach -t deploy
If you only have one session, you can skip the name:
tmux attach
Verify which sessions are running:
tmux list-sessions
deploy: 1 windows (created Thu Mar 19 10:00:00 2026) (attached)
background: 1 windows (created Thu Mar 19 10:05:00 2026)
The (attached) label tells you which session your terminal is connected to.
Killing sessions
When you are done with a session, destroy it:
tmux kill-session -t background
Verify it is gone:
tmux list-sessions
To kill all sessions and stop the tmux server entirely:
tmux kill-server
Renaming sessions
From inside a session, press:
Ctrl-b $
Type the new name and press Enter. Useful when you started a session without a name and tmux assigned it a number.
How do I use tmux windows to organize tasks?
Windows are tabs within a session. Each window runs its own shell. Use them to separate tasks that don't need to be visible at the same time.
Create a new window:
Ctrl-b c
The status bar updates to show the new window. The asterisk (*) marks the active window:
[deploy] 0:bash 1:bash*
Switching between windows
By number:
Ctrl-b 0 # Go to window 0
Ctrl-b 1 # Go to window 1
By cycling:
Ctrl-b n # Next window
Ctrl-b p # Previous window
Renaming a window
Ctrl-b ,
Type a meaningful name like "logs" or "editor" and press Enter. Named windows make the status bar readable when you have several open.
Closing a window
Type exit in the shell, or press:
Ctrl-b &
tmux asks for confirmation before closing.
How do I split the terminal into panes?
Panes split a window into multiple terminals visible at the same time. This is where tmux shines for VPS administration: watch logs in one pane while running commands in another.
Split the current pane horizontally (top and bottom):
Ctrl-b "
Split the current pane vertically (left and right):
Ctrl-b %
After splitting, you have two panes. The green border highlights the active pane.
How do I navigate and resize tmux panes?
Move between panes with the arrow keys:
Ctrl-b ↑ # Move to pane above
Ctrl-b ↓ # Move to pane below
Ctrl-b ← # Move to pane left
Ctrl-b → # Move to pane right
Resize panes by holding the prefix and pressing arrow keys:
Ctrl-b Ctrl-↑ # Resize pane up
Ctrl-b Ctrl-↓ # Resize pane down
Ctrl-b Ctrl-← # Resize pane left
Ctrl-b Ctrl-→ # Resize pane right
Zooming a pane
Need one pane full-screen temporarily? Toggle zoom:
Ctrl-b z
Press it again to restore the split layout. The status bar shows a Z next to the window name when a pane is zoomed.
Closing a pane
Type exit in the pane, or press:
Ctrl-b x
tmux asks for confirmation. If you close the last pane in a window, the window closes too.
Swapping panes
Rotate pane positions:
Ctrl-b { # Move current pane left/up
Ctrl-b } # Move current pane right/down
How do I use tmux copy mode to scroll and search?
By default, you cannot scroll up in a tmux pane with your mouse wheel or Page Up. Copy mode gives you scrollback, search, and text selection.
Enter copy mode:
Ctrl-b [
You are now in copy mode. The top-right corner shows your position in the scrollback buffer (e.g., [0/500]).
Navigating in copy mode
tmux uses emacs-style keys by default. If your EDITOR or VISUAL environment variable contains "vi," it uses vi-style keys instead.
Emacs mode (default):
| Action | Key |
|---|---|
| Scroll up | Ctrl-Up or Page Up |
| Scroll down | Ctrl-Down or Page Down |
| Move cursor | Arrow keys |
| Start of line | Ctrl-a |
| End of line | Ctrl-e |
| Search forward | Ctrl-s |
| Search backward | Ctrl-r |
| Start selection | Ctrl-Space |
| Copy selection | Alt-w |
| Exit copy mode | q |
Vi mode:
| Action | Key |
|---|---|
| Scroll up | Ctrl-u (half page) |
| Scroll down | Ctrl-d (half page) |
| Move cursor | h j k l |
| Search forward | / |
| Search backward | ? |
| Start selection | Space |
| Copy selection | Enter |
| Exit copy mode | q |
After copying, paste with:
Ctrl-b ]
Sharp eyes: copy mode is how you search through long command output. If a build fails and the error scrolled off-screen, enter copy mode and search backward with Ctrl-r (emacs) or ? (vi).
How do I customize tmux with .tmux.conf?
tmux reads its configuration from ~/.tmux.conf when the server starts. On tmux 3.2 and later, it also checks ~/.config/tmux/tmux.conf.
This configuration works well for VPS administration. Each line is explained.
Create or edit the config file:
nano ~/.tmux.conf
# -- General -----------------------------------------------------------------
# Change prefix from Ctrl-b to Ctrl-a (easier to reach)
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# Start window numbering at 1 (0 is far from the prefix key)
set -g base-index 1
setw -g pane-base-index 1
# Renumber windows when one is closed (no gaps)
set -g renumber-windows on
# Increase scrollback buffer (default is 2000 lines)
set -g history-limit 50000
# Reduce escape delay (snappier key response)
set -g escape-time 10
# Enable mouse support (scroll, click panes, resize)
set -g mouse on
# -- Display -----------------------------------------------------------------
# 256-color terminal support
set -g default-terminal "tmux-256color"
# -- Key Bindings ------------------------------------------------------------
# Split panes with | and - (more intuitive than " and %)
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %
# Navigate panes with Alt-arrow (no prefix needed)
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
# Reload config with prefix r
bind r source-file ~/.tmux.conf \; display-message "Config reloaded"
# -- Copy Mode ---------------------------------------------------------------
# Use vi keys in copy mode
setw -g mode-keys vi
# -- Status Bar --------------------------------------------------------------
# Status bar position
set -g status-position bottom
# Update interval (seconds)
set -g status-interval 5
# Clean status bar colors
set -g status-style "bg=colour235,fg=colour136"
set -g status-left "#[fg=colour235,bg=colour136] #S #[fg=colour136,bg=colour235] "
set -g status-right "#[fg=colour136] %H:%M %d-%b-%Y "
set -g status-left-length 20
Save and exit. Apply the config to a running tmux session:
tmux source-file ~/.tmux.conf
Verify by pressing Ctrl-a (the new prefix) instead of Ctrl-b. If it works, the config loaded correctly.
Set proper permissions on the config file:
chmod 600 ~/.tmux.conf
ls -la ~/.tmux.conf
-rw------- 1 youruser youruser 1234 Mar 19 10:00 /home/youruser/.tmux.conf
The 600 permission means only your user can read and write the file. This matters if you store any custom scripts or sensitive paths in your tmux config.
Key changes from defaults explained:
- Prefix
Ctrl-aputs the key under your left pinky.Ctrl-brequires a stretch. This is the most common rebind. base-index 1means windows start at 1 instead of 0. PressingCtrl-a 1for the first window is natural.history-limit 50000stores 50,000 lines of scrollback per pane. The default 2,000 is too small for log tailing.escape-time 10reduces the delay tmux waits after receiving an Escape key. The default (500ms) makes Vim feel sluggish inside tmux.-c "#{pane_current_path}"on split bindings opens new panes in the same directory you are currently in, instead of the home directory.mode-keys viswitches copy mode to vi-style navigation. Change toemacsif you prefer.
How do I set up tmux plugins with tpm?
tmux Plugin Manager (tpm) lets you install plugins from GitHub. Two plugins worth knowing:
- tmux-resurrect saves and restores tmux sessions across server reboots
- tmux-continuum auto-saves sessions at regular intervals
Installing tpm
Clone the repository:
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Add these lines to the bottom of ~/.tmux.conf:
# -- Plugins -----------------------------------------------------------------
# Plugin manager
set -g @plugin 'tmux-plugins/tpm'
# Save/restore sessions across reboots
set -g @plugin 'tmux-plugins/tmux-resurrect'
# Auto-save sessions every 15 minutes
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-restore 'on'
# Initialize tpm (keep this line at the very bottom)
run '~/.tmux/plugins/tpm/tpm'
Reload the config:
tmux source-file ~/.tmux.conf
Install the plugins from inside tmux:
Ctrl-a I
That is a capital I. tpm fetches and installs the plugins. You see a message when it finishes.
Verify the plugins installed:
ls ~/.tmux/plugins/
tmux-continuum tmux-resurrect tpm
Using tmux-resurrect
Save your current session layout:
Ctrl-a Ctrl-s
Restore after a reboot:
Ctrl-a Ctrl-r
tmux-resurrect saves window layouts, pane splits, and the current directory of each pane. With tmux-continuum enabled, this happens automatically every 15 minutes.
How do I handle nested tmux sessions over SSH?
When you run tmux locally and SSH into a VPS that also runs tmux, you end up with tmux inside tmux. Both instances respond to the same prefix key. Your key presses go to the outer (local) tmux instead of the inner (remote) one.
The solution: send the prefix key through to the inner session by pressing the prefix twice.
Ctrl-a Ctrl-a d # Detach the inner (remote) session
The first Ctrl-a is captured by the outer tmux. The second Ctrl-a gets forwarded to the inner tmux as its prefix. Then d detaches the inner session.
A cleaner approach: use different prefix keys. Keep Ctrl-a locally and leave Ctrl-b as the default on remote servers. Then there is no conflict.
If you already changed the prefix on both sides, add a toggle to your local ~/.tmux.conf:
# Toggle prefix passthrough with F12
bind -T root F12 \
set prefix None \;\
set key-table off \;\
set status-style "bg=colour238,fg=colour240" \;\
display-message "Prefix OFF (sending to inner)"
bind -T off F12 \
set -u prefix \;\
set -u key-table \;\
set -u status-style \;\
display-message "Prefix ON (local)"
Press F12 to disable the local prefix and pass all keys to the remote tmux. Press F12 again to re-enable it. The dimmed status bar gives you a visual indicator of which mode you are in.
How do I create scripted tmux layouts for server administration?
Instead of manually splitting panes each time you SSH in, script your layout. This creates a repeatable workspace with one command.
Create a script:
nano ~/tmux-admin.sh
#!/usr/bin/env bash
# tmux-admin.sh: three-pane admin layout
SESSION="admin"
# Kill old session if it exists
tmux kill-session -t "$SESSION" 2>/dev/null
# Create session with first window named "monitor"
tmux new-session -d -s "$SESSION" -n "monitor"
# Top pane: system monitoring
tmux send-keys -t "$SESSION:monitor" "htop" C-m
# Split horizontally: bottom pane for logs
tmux split-window -v -t "$SESSION:monitor"
tmux send-keys -t "$SESSION:monitor.1" "journalctl -f" C-m
# Split bottom pane vertically: right pane for shell
tmux split-window -h -t "$SESSION:monitor.1"
# Create second window for a working shell
tmux new-window -t "$SESSION" -n "work"
# Select the first window
tmux select-window -t "$SESSION:monitor"
# Select the bottom-right pane (the empty shell)
tmux select-pane -t "$SESSION:monitor.2"
# Attach to the session
tmux attach -t "$SESSION"
Make it executable and run it:
chmod 700 ~/tmux-admin.sh
~/tmux-admin.sh
You get a three-pane layout: htop at the top, journalctl -f at the bottom-left, and an empty shell at the bottom-right. A second window named "work" is available for ad-hoc commands.
Sharp eyes: the C-m at the end of send-keys is a carriage return. It presses Enter to execute the command.
Auto-starting tmux on boot with systemd
For long-running admin sessions, create a systemd service:
sudo nano /etc/systemd/system/tmux-admin@.service
[Unit]
Description=tmux admin session for %i
After=network.target
[Service]
Type=forking
User=%i
ExecStart=/usr/bin/tmux new-session -d -s admin
ExecStop=/usr/bin/tmux kill-session -t admin
[Install]
WantedBy=multi-user.target
Enable and start it for your user:
sudo systemctl enable --now tmux-admin@youruser.service
Verify it is running:
sudo systemctl status tmux-admin@youruser.service
● tmux-admin@youruser.service - tmux admin session for youruser
Loaded: loaded (/etc/systemd/system/tmux-admin@.service; enabled)
Active: active (running)
Now a tmux session named "admin" starts automatically on boot. Attach to it after SSH:
tmux attach -t admin
Security: tmux socket permissions
tmux creates a socket file to communicate between its server and client processes. By default, this socket lives in a directory under /tmp (e.g., /tmp/tmux-1000/).
Check your socket directory:
ls -la /tmp/tmux-$(id -u)/
srwxrwx--- 1 youruser youruser 0 Mar 19 10:00 default
The socket directory is owned by your user with permissions that prevent other users from accessing it. This means other users on the same server cannot attach to your tmux sessions.
However, if you run tmux as root, any process running as root can attach. Avoid running tmux as root for everyday work. SSH in as your regular user and use sudo for individual commands that need it.
If you need to share a tmux session (for pair programming or mentoring), use a shared socket explicitly:
tmux -S /tmp/shared-session new-session -s pair
chmod 770 /tmp/shared-session
Then the other user attaches with:
tmux -S /tmp/shared-session attach -t pair
Revoke access when done:
chmod 700 /tmp/shared-session
Something went wrong?
tmux: command not found
The package did not install. Run sudo apt install -y tmux and check for errors.
"no server running on /tmp/tmux-1000/default"
No tmux session exists. Start one with tmux new-session -s main.
Keys not responding / wrong prefix
Check which prefix is active: tmux show-options -g prefix. If you changed the prefix in .tmux.conf, reload with tmux source-file ~/.tmux.conf.
Mouse scroll not working
Add set -g mouse on to ~/.tmux.conf and reload. On tmux versions before 2.1, the option was set -g mode-mouse on (different syntax).
Colors look wrong inside tmux
Set set -g default-terminal "tmux-256color" in ~/.tmux.conf. If your terminal emulator supports true color (24-bit), add:
set -as terminal-overrides ",*-256color:Tc"
Session lost after reboot tmux sessions do not survive reboots by default. Use tmux-resurrect and tmux-continuum (covered above), or create a systemd service to auto-start a session.
Vim is slow to exit insert mode
The escape-time default (500ms) causes this. Set set -g escape-time 10 in ~/.tmux.conf.
Check tmux logs for deeper issues:
tmux start-server \; show-messages
Or look at system logs:
journalctl -u tmux-admin@youruser.service -f
tmux key bindings quick reference
This table uses the default prefix Ctrl-b. If you rebound the prefix to Ctrl-a (as in the config above), use that instead.
Sessions
| Action | Keybinding | Command |
|---|---|---|
| New named session | tmux new-session -s name |
|
| Detach | Ctrl-b d |
tmux detach |
| List sessions | Ctrl-b s |
tmux list-sessions |
| Attach | tmux attach -t name |
|
| Rename session | Ctrl-b $ |
tmux rename-session |
| Kill session | tmux kill-session -t name |
Windows
| Action | Keybinding | Command |
|---|---|---|
| New window | Ctrl-b c |
|
| Next window | Ctrl-b n |
|
| Previous window | Ctrl-b p |
|
| Window by number | Ctrl-b 0-9 |
|
| Rename window | Ctrl-b , |
|
| Close window | Ctrl-b & |
|
| List windows | Ctrl-b w |
Panes
| Action | Keybinding | Command |
|---|---|---|
| Split horizontal | Ctrl-b " |
|
| Split vertical | Ctrl-b % |
|
| Navigate | Ctrl-b Arrow |
|
| Resize | Ctrl-b Ctrl-Arrow |
|
| Zoom toggle | Ctrl-b z |
|
| Close pane | Ctrl-b x |
|
| Swap pane | Ctrl-b { / Ctrl-b } |
Copy Mode
| Action | Keybinding |
|---|---|
| Enter copy mode | Ctrl-b [ |
| Paste buffer | Ctrl-b ] |
| Search (emacs) | Ctrl-r (backward) / Ctrl-s (forward) |
| Search (vi) | ? (backward) / / (forward) |
| Exit | q |
Other
| Action | Keybinding |
|---|---|
| Command prompt | Ctrl-b : |
| List all keybindings | Ctrl-b ? |
| Clock mode | Ctrl-b t |
Copyright 2026 Virtua.Cloud. All rights reserved. This content is original work by the Virtua.Cloud team. Reproduction, republication, or redistribution without written permission is prohibited.
Ready to try it yourself?
Deploy your own server in seconds. Linux, Windows, or FreeBSD.
See VPS Plans