tmux for Beginners: Never Lose a Terminal Session Again
Picture this: you’re SSH’d into a server, running a long scan or a big download. Your Wi-Fi hiccups for two seconds. Connection dropped — and your command died with it. tmux makes that impossible. It’s a terminal multiplexer: it keeps your sessions alive on the remote machine, detachable and re-attachable anytime.
Why tmux Matters
When you run a command over SSH, it’s tied to your connection. Kill the connection, kill the command. tmux runs your terminal inside a persistent session on the server. Disconnect, go to sleep, reconnect tomorrow — your work is exactly where you left it. It’s also how pros juggle multiple terminals in one window.
Installing tmux
sudo apt install tmux # Debian/Ubuntusudo dnf install tmux # Fedorasudo pacman -S tmux # Arch
Your First Session
tmux new -s work # start a named session called "work"
You’re now inside tmux. Everything looks normal — that’s the point. Run any command. Now the magic: press Ctrl+b, release, then press d. You’re detached — back at your normal shell, but the session keeps running in the background.
Reconnect anytime:
tmux attach -t work # reattach to the "work" sessiontmux ls # list all sessions
The Essential Shortcuts
Every tmux command starts with the prefix Ctrl+b, then a key:
- Ctrl+b d — detach (session keeps running)
- Ctrl+b c — create a new window
- Ctrl+b n / Ctrl+b p — next / previous window
- Ctrl+b % — split pane vertically
- Ctrl+b ” — split pane horizontally
- Ctrl+b arrow keys — move between panes
- Ctrl+b x — close the current pane
- Ctrl+b , — rename the current window
Try this: split your terminal into panes, run htop in one and a log tail in another. One SSH connection, full dashboard.
The Killer Feature: Surviving Disconnects
- SSH into your server.
- tmux attach -t work (or start a new session).
- Launch your long-running command — a backup, a scan, a download.
- Detach with Ctrl+b d and log out. The command keeps running.
- Tomorrow: SSH in, tmux attach -t work — everything’s still there.
No more nohup, no more dead scripts, no more babysitting SSH.
Pro Tips
- Name sessions by purpose: tmux new -s backup, tmux new -s monitoring.
- Kill a finished session: tmux kill-session -t work.
- Scroll in tmux: Ctrl+b [ enters copy mode; q exits. (Or enable mouse mode in ~/.tmux.conf with set -g mouse on.)
tmux takes ten minutes to learn and pays off forever. If you touch remote servers at all, this is non-negotiable.



Comments
Post a Comment