Tmux Cheat Sheet: From Beginners to Advanced Level

Tmux Cheat Sheet: From Beginners to Advanced Level

TL;DR: This Tmux cheat sheet from beginners to advanced level is your go-to reference for mastering the terminal multiplexer that every sysadmin, developer, and DevOps engineer should know. Tmux lets you manage multiple sessions, windows, and panes within a single terminal—enabling persistent workflows, easier multitasking, and powerful automation. Whether you’re just starting or looking to optimize with advanced scripting, this comprehensive guide covers all key commands, practical examples, and production-grade best practices to help you boost productivity and avoid common pitfalls.


TL;DR Summary

Tmux is a powerful terminal multiplexer that lets you run, manage, and recover persistent terminal sessions. It’s indispensable for anyone who works on remote servers, needs to organize multiple shell environments, or wants to automate complex workflows. Here are the essential commands you’ll use daily:

# Start a new (unnamed) tmux session
$ tmux
# (Opens a new tmux session with a default name)

# Start a new session named 'deploy'
$ tmux new-session -s deploy
# (Opens a session called 'deploy' for easy identification)

# Attach to the most recently used session
$ tmux attach
# (Reattaches to your last session, resuming work instantly)

# List all active tmux sessions
$ tmux list-sessions
deploy: 1 windows (created Thu Jun 13 10:00:00 2024) [80x24]
web: 2 windows (created Thu Jun 13 09:45:00 2024) [80x24]

# Kill a session named 'web'
$ tmux kill-session -t web
# (Closes the 'web' session and all processes within)

Distro installation:

  • RHEL/CentOS: yum install tmux (EPEL repo for latest)
  • Debian/Ubuntu: apt install tmux
  • Arch: pacman -S tmux (generally latest version)

WARNING: Killing a session (kill-session) will terminate all processes running in that session. Always detach (Ctrl-b d) before closing your terminal, and name your sessions for easier management.

Three common mistakes:

  1. Forgetting to detach before closing your terminal, leaving orphaned processes.
  2. Not naming sessions, making it hard to manage or reattach.
  3. Accidentally killing the wrong session with kill-session.

Introduction to Tmux

Tmux stands for “terminal multiplexer,” a tool that lets you manage multiple terminal sessions from a single window. This means you can split terminals into panes, create and navigate between multiple windows, and even detach from a session and reattach later—perfect for remote SSH work or long-running jobs. For system administrators and developers, Tmux is essential for:

  • Keeping sessions alive over flaky SSH connections
  • Organizing different tasks (logs, shells, editors) in one interface
  • Running background processes or monitoring scripts without losing state

Key commands to get started:

# Check your current tmux version
$ tmux -V
tmux 3.2a
# (Always verify version, as features differ between releases)

# Force 256-color support (for enhanced text highlighting)
$ tmux -2

# Start tmux with a custom configuration file
$ tmux -f /etc/tmux.conf

# Start tmux and immediately run a command (e.g., htop)
$ tmux -c "htop"

# Start tmux with verbose logging (useful for troubleshooting)
$ tmux -v
# (Logs are created as tmux-client-PID.log and tmux-server-PID.log)

NOTE: Running tmux as root is discouraged unless you must manage system-wide processes; user-level sessions are safer and prevent accidental system changes.

Distro notes:

  • Some distributions provide older tmux versions by default—always check your version with tmux -V.
  • Custom config files can be specified with -f, and the default is usually ~/.tmux.conf or /etc/tmux.conf.

Common mistakes:

  1. Using outdated tmux versions that lack modern features (e.g., mouse support).
  2. Overwriting the default config without keeping a backup.
  3. Running tmux as root when not needed, which can lead to permission issues or security risks.

Prerequisites

To use Tmux effectively, you need the following:

  • A compatible terminal: Your $TERM must support 256 colors for best results.
  • Tmux installed: Should be a recent version (preferably 2.x or higher).
  • User configuration: Optionally, a ~/.tmux.conf for custom key bindings and options.

How to verify your setup:

# Check if tmux is installed and where it's located
$ which tmux
/usr/bin/tmux

# Check your terminal type
$ echo $TERM
xterm-256color
# (Ensures color support and pane rendering)

# Install tmux on Ubuntu/Debian
$ sudo apt install tmux

# Install tmux on CentOS/RHEL (EPEL repo may be required)
$ sudo yum install tmux

# Check for a user-specific configuration file
$ ls ~/.tmux.conf
/home/alice/.tmux.conf

WARNING: Installing tmux from unofficial sources or random scripts may introduce vulnerabilities. Always use your OS package manager or trusted repos.

Distro notes:

  • RHEL/CentOS: For the latest tmux, enable the EPEL repository.
  • Debian/Ubuntu: Tmux is in the main repositories but may lag behind upstream.
  • Arch: Official repos almost always carry the latest version.

Common mistakes:

  1. Not verifying your terminal supports 256 colors, leading to poor display.
  2. Using a broken or missing .tmux.conf, causing errors at tmux startup.
  3. Installing tmux from untrusted sources or unofficial scripts.

Basic Tmux Commands

Once installed, here’s how you start using tmux for basic session and pane management:

# Create a named session called 'web01'
$ tmux new-session -s web01

# Attach to an existing session named 'web01'
$ tmux attach -t web01

# Detach from your current session (returns you to the normal shell)
Ctrl-b d

# Split the current pane horizontally (side by side)
Ctrl-b %

# Split the current pane vertically (top/bottom)
Ctrl-b "

# Move to the pane on the right
Ctrl-b l

# List all windows (tabs) in your current session
$ tmux list-windows
0: bash* (2 panes) [80x24] [layout b25a,80x24,0,0[80x12,0,0,0,80x11,0,13,1]] @0 (active)

# Create a new window (like a tab)
Ctrl-b c

Why these flags matter:

  • -s when starting a session lets you easily identify and manage sessions later.
  • -t specifies the target session for commands like attach.
  • Ctrl-b is the default tmux command prefix; you can change this in your config.

TIP: Customize your ~/.tmux.conf to remap the default prefix key if you find Ctrl-b awkward. Many users prefer Ctrl-a for faster access.

Distro notes:

  • Key bindings are consistent across all major distributions.
  • Some commands (like pane splitting) may require tmux 2.x or newer.

Common mistakes:

  1. Forgetting to detach, leading to lost work if your SSH session drops.
  2. Not naming sessions, making it impossible to differentiate active sessions.
  3. Confusing which key binding splits vertically vs. horizontally.

Intermediate Tmux Features

Once you’re comfortable with basic commands, you’ll want to take advantage of session and window management, as well as dynamic config reloading:

# List all tmux sessions (great for multi-project workflows)
$ tmux list-sessions
web01: 2 windows (created Thu Jun 13 10:00:00 2024) [80x24]
db01: 1 windows (created Thu Jun 13 09:45:00 2024) [80x24]

# Rename a session from 'web01' to 'frontend'
$ tmux rename-session -t web01 frontend

# Kill (terminate) a session called 'db01'
$ tmux kill-session -t db01

# Move window 1 from session 'frontend' to session 'backend'
$ tmux move-window -s frontend:1 -t backend

# Reload your tmux configuration after editing ~/.tmux.conf
$ tmux source-file ~/.tmux.conf

Why these flags matter:

  • -t and -s precisely control which sessions/windows you’re working with.
  • source-file instantly applies configuration changes without restarting tmux.

WARNING: Killing a session or moving windows will disrupt all running processes in that session or window—always double-check your targets.

Distro notes:

  • Some commands, like move-window, may not be available in very old tmux versions (ensure 2.0+).
  • The location of configuration files can differ; user configs take precedence over system-wide configs.

Common mistakes:

  1. Moving windows to the wrong session, causing workflow confusion.
  2. Forgetting to reload your config after changes—use source-file every time.
  3. Killing the wrong session, which can cause loss of work or disrupt teammates.

Advanced Tmux Techniques

Tmux is more than just panes and windows—it’s scriptable, customizable, and extensible with plugins. Here’s how to take your workflow to the next level:

# Send the command 'ls -l' to pane 1 in window 0 of session 'web01'
$ tmux send-keys -t web01:0.1 "ls -l" C-m
# (Sends 'ls -l' and simulates pressing Enter)

# Capture the last 100 lines of pane 0 in session 'web01'
$ tmux capture-pane -t web01:0.0 -p -S -100
[output of last 100 lines]

# Run a shell script within the tmux context
$ tmux run-shell "/usr/local/bin/deploy.sh"
# (Executes deploy.sh as if typed in the pane)

# Set mouse support globally (allows click-to-select panes/windows)
$ tmux set-option -g mouse on

# Bind F12 to split window vertically (overrides default behavior)
$ tmux bind-key -n F12 split-window -v

Why these flags matter:

  • send-keys is powerful for automation but must be targeted carefully.
  • capture-pane with -p (print) and -S -100 (start 100 lines from the bottom) is useful for logging or debugging.
  • set-option -g makes changes global (for all sessions).
  • bind-key -n creates key bindings that work outside the tmux prefix.

TIP: Use tmux send-keys in scripts to automate repetitive tasks across multiple panes—just be sure you’re targeting the correct pane to avoid surprises.

Distro notes:

  • Advanced features like mouse support and run-shell generally require tmux 2.1 or newer.
  • Mouse mode may also require enabling support in your terminal emulator.

Common mistakes:

  1. Overwriting existing key bindings, unintentionally disabling important shortcuts.
  2. Using send-keys on the wrong pane, causing commands to run in the wrong context.
  3. Forgetting to enable mouse support in both tmux and your terminal.

Common Mistakes & Gotchas

Even experienced tmux users hit these roadblocks. Here’s how to avoid the most frequent missteps:

# Accidentally killing the wrong session (e.g., 'prod' instead of 'staging')
$ tmux kill-session -t prod

# Not reloading configuration after edits (changes won’t take effect)
$ tmux source-file ~/.tmux.conf

# Detaching (Ctrl-b d) instead of killing a session (session remains running)
Ctrl-b d

# Not naming sessions, leading to confusion among multiple unnamed ('0', '1', ...) sessions
$ tmux new-session

# Using default key bindings without customizing for your workflow
$ tmux bind-key -n F9 new-window
# (Custom key binding for quick new window creation)

WARNING: Killing sessions or windows without saving work can cause immediate data loss. Always ensure you’ve saved or detached correctly.

Common errors and their consequences:

  1. Killing the wrong session or window—double-check your targets.
  2. Not saving your work before detaching or killing sessions.
  3. Failing to customize key bindings, resulting in lost productivity.

Security & Production Considerations

When using tmux in shared or production environments, security is paramount. Tmux communicates via Unix domain sockets, which, if left insecure, can be exploited for privilege escalation or session hijacking.

# Start tmux with a custom socket name (isolates your sessions)
$ tmux -L secure

# Start tmux with a custom socket path (e.g., in a private directory)
$ tmux -S /var/run/tmux.sock

# Secure the tmux socket directory (only accessible by your user)
$ chmod 700 /tmp/tmux-1000

# Check socket permissions to ensure they’re restricted
$ ls -ld /tmp/tmux-1000
drwx------ 2 alice alice 4096 Jun 13 10:00 /tmp/tmux-1000

# Kill all tmux sessions (use with caution in shared environments)
$ tmux kill-server

Why these flags matter:

  • -L and -S let you isolate tmux sockets from other users or system processes.
  • chmod 700 ensures only your user can access your tmux session sockets.
  • kill-server terminates all tmux sessions for all users sharing that socket.

WARNING: Insecure socket permissions can allow other users on the same server to hijack your tmux sessions. Always secure your socket directory and never leave tmux running as root unless absolutely necessary.

Distro notes:

  • Socket location defaults to /tmp/tmux-UID, but may vary on hardened systems.
  • SELinux or AppArmor profiles can restrict socket access—check your system policies in production.

Common mistakes:

  1. Leaving tmux sockets or directories world-readable.
  2. Running tmux as root unnecessarily, increasing risk of system compromise.
  3. Not securing custom socket paths if using -S.

Further Reading

To master Tmux beyond this cheat sheet, consult the following resources:

# Read the official tmux man page (most comprehensive reference)
$ man tmux

# Get a summary of command-line options and usage
$ tmux -h

# Official tmux GitHub repository (for latest releases and issues)
https://github.com/tmux/tmux

# Arch Wiki tmux page (excellent community-maintained documentation)
https://wiki.archlinux.org/title/tmux

# Explore community scripts and plugin ecosystem
https://github.com/tmux-plugins

TIP: The Arch Wiki is a goldmine for troubleshooting and advanced configuration tips—check it even if you’re not an Arch user.

Additional tips:

  • Always consult the man tmux page for advanced options and up-to-date syntax.
  • The Arch Wiki remains one of the most thorough and current sources for tmux usage and troubleshooting.
  • Use official or widely trusted plugins for session management, status lines, and productivity enhancements.

Common mistakes:

  1. Not consulting the man page for advanced features and troubleshooting.
  2. Relying on outdated blogs or guides—always check dates and versions.
  3. Installing untrusted or outdated plugins that may break your workflow or introduce vulnerabilities.

Conclusion

Whether you’re a new user or a seasoned sysadmin, this Tmux cheat sheet from beginners to advanced level equips you to use tmux to its full potential. With strong session management, pane/window organization, and advanced scripting, tmux is an essential tool for anyone who values efficiency and reliability in the terminal. Always secure your sessions, customize your environment, and reference the latest documentation to stay productive and safe. Happy multiplexing!

 

Man Page

You might be interested in

Linux Security Hardening Practices Tutorial

Advanced Linux File Permissions Explained

How to use Find Command at its best in Linux

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *