tmux Essentials for Long-Running Sessions
Keep terminal sessions alive across disconnects with tmux: sessions, windows, panes, and persistence.
Netbay Cloud Team
Netbay Engineering
On this page
Any developer who has run a build, a Tailwind watcher, or a database import over SSH knows the pain of a dropped connection killing the process. tmux, the terminal multiplexer, solves this by running your shell in a persistent server that survives disconnects. You can detach from a session, reconnect later, and find the process exactly where you left it.
Starting and Detaching
The core operations are starting a session, detaching, reattaching, and killing:
tmux new -s work
tmux new -s web -d
tmux ls
tmux attach -t work
tmux kill-session -t worktmux new -s work creates a session named work. -d starts it detached so it keeps running in the background. tmux attach -t work reattaches to the running session. This is the entire workflow for surviving SSH disconnects: start a session, work, detach with the prefix sequence, and reattach later.
The default prefix is Ctrl-b. Press Ctrl-b then d to detach. Ctrl-b then c creates a new window. Ctrl-b then n and p move between windows, and Ctrl-b then 0-9 jumps to a numbered window.
Windows and Panes
Windows are like tabbed terminal sessions within your tmux session. Panes split a window into regions:
Ctrl-b c create a new window
Ctrl-b , rename the current window
Ctrl-b % split vertically into two panes
Ctrl-b " split horizontally into two panes
Ctrl-b arrow move between panes
Ctrl-b x close the current paneA common layout is one pane running a dev server, one pane running the build watcher, and one pane for ad-hoc commands. This keeps context visible without tab-switching.
Capture and copy inside tmux uses the prefix plus brackets: Ctrl-b [ enters copy mode for scrolling the buffer, then q exits.
Persistence for Long-Running Work
A typical detached workflow for a build that takes hours looks like this:
tmux new -s build -d
tmux send-keys -t build "npm run build:prod" Enter
tmux attach -t buildThe send-keys command injects a keystroke into a detached session, so you can start the build, detach, reconnect later, and read the full output in the scrollback buffer. This is far more robust than running the command with a simple background & and hoping it survives.
For provisioning scripts that must survive as well:
tmux new -s deploy
./deploy.sh
Ctrl-b d
tmux attach -t deployRun the deploy in the session, detach, and come back hours later to confirm the output.
Scrollback and Search
Long outputs scroll past the visible area. In copy mode you can page through the entire scrollback:
Ctrl-b [
PageUp / PageDown scroll
/ pattern search in scrollback
q exit copy modeSearch in scrollback is especially useful for locating a specific error in an hours-long log stream without re-running the command.
Configuration
Purists write a small ~/.tmux.conf for convenience:
set -g mouse on
set -g base-index 1
set -g history-limit 10000
bind r source-file ~/.tmux.confset -g mouse on enables mouse scrolling and pane selection. base-index 1 numbers windows from 1 instead of 0. history-limit 10000 keeps 10,000 lines of scrollback per pane.
Takeaway
tmux turns flaky SSH connections from a business risk into a minor inconvenience. Sessions outlive the connection, so long builds and deploys keep running no matter what. Try tmux on your next long-running task on a Netbay Linux VPS at netbayhosts.in.
Keep reading
Follow along on a real VPS
Deploy Linux in under 60 seconds
These guides are written against Ubuntu, Debian, and RHEL-family images — the same ones on NetBay.
Deploy an instance