How to Use tmux: Keep Programs Running After SSH Closes
Learn how to use tmux on a Linux server: keep programs running after SSH closes, detach and reattach sessions, split panes, scroll and fix common errors.

Contents
- Why programs stop when SSH closes
- Installing tmux
- Sessions, windows and panes
- The basics: start, detach, reattach
- Working with windows
- Splitting a window into panes
- Scrolling and copy mode
- A small ~/.tmux.conf
- Example: a game server in tmux
- tmux vs screen, nohup and systemd
- Shortcut table
- Common errors
- tmux on Nodesty servers
Once you know how to use tmux, a dropped SSH connection no longer takes your work with it. tmux keeps your programs running on the server after you close the terminal, lets you return to them hours or days later and gives you several windows and split panes inside a single connection.
This guide covers why programs stop when SSH closes, installing tmux, the session, window and pane model, the basic commands, scrolling, a small configuration file, a game server example, how tmux compares to screen, nohup and systemd, a shortcut table and the most common errors.
Why programs stop when SSH closes
When your SSH connection closes, the terminal your shell was attached to disappears. The system sends a hangup signal (SIGHUP) to the shell, the shell passes it on to the programs it started, and most programs exit when they receive it. That's why a game server, a long copy or an upgrade stops the moment your connection drops; the usual causes of drops are in our SSH connection errors guide.
tmux solves this with a server process that runs on the machine and isn't tied to your SSH connection. Your programs run inside that tmux server, and what you see is only a client attached to it. When the connection closes, only the client goes away.
Installing tmux
sudo apt install tmux # Ubuntu / Debian
sudo dnf install tmux # AlmaLinux / Rocky Linux
tmux -V
Install it on the server, not on your own computer: the session has to live where the program runs.
Sessions, windows and panes
- Session: A workspace that keeps running in the background. You detach from it and attach to it again. Give each job its own named session, such as
minecraftorbackup. - Window: A full-screen terminal inside a session, like a browser tab. A session can have many windows.
- Pane: A window can be split into panes so that you see several terminals side by side.
The green status line at the bottom shows the session name on the left and the list of windows next to it; the current window is marked with *.
The basics: start, detach, reattach
Every tmux shortcut starts with the prefix Ctrl + B: press it, release it, then press the next key. Keys are case-sensitive, so d and D do different things.
tmux new -s work # start a session named work
tmux ls # list sessions
tmux attach -t work # return to the session
tmux kill-session -t work # end the session and everything in it
Start a session, run your command and press Ctrl + B, then d to detach. You're back in your normal shell and can close the SSH connection; the command keeps running. If the connection drops by itself, the session is detached automatically. After logging in again, tmux ls shows what is running:
work: 1 windows (created Sun Nov 15 10:12:03 2026)
Detaching is not the same as exiting. If you type exit or press Ctrl + D, the shell closes, and when the last shell in a session closes, the session ends. tmux new -A -s work attaches to the session if it already exists and creates it if it doesn't, which makes it a handy command to remember.
Working with windows
Press Ctrl + B, then c to open a new window. Switch with n (next), p (previous) or a number from 0 to 9, and press w for a list you can pick from. Rename the current window with , so the status line shows logs instead of bash. & closes the window after asking for confirmation.
A typical layout is one window for the program itself, one for its log files and one for htop. For other everyday commands, see our Linux commands guide.
Splitting a window into panes
Ctrl + B, then % splits the current pane into a left and a right half; " splits it into a top and a bottom half. Move between panes with Ctrl + B and an arrow key. z zooms the current pane to the full window and the same key brings the layout back. x closes the pane after asking for confirmation, and typing exit in it does the same. To resize a pane, press Ctrl + B and then hold Ctrl while pressing an arrow key.
Scrolling and copy mode
Inside tmux, the scrollbar of your terminal doesn't show older output. Use copy mode instead: press Ctrl + B, then [, move with the arrow keys or Page Up and Page Down, and press q to return. Ctrl + B, then Page Up enters copy mode and scrolls up one page in one step. Text you copy in copy mode is pasted with Ctrl + B, then ].
A small ~/.tmux.conf
tmux works without any configuration. These few lines in ~/.tmux.conf make daily use more comfortable:
set -g mouse on
set -g history-limit 20000
set -g base-index 1
setw -g pane-base-index 1
mouse onlets you scroll with the wheel, click a pane to select it and drag pane borders. To select text with your terminal's own selection while it's on, holdShiftin most terminals.history-limitsets how many lines of scrollback each pane keeps; the default is 2,000. It applies to panes created after the change.base-indexandpane-base-indexnumber windows and panes from 1 instead of 0, which matches the keyboard layout better.
The file is read when the tmux server starts. To apply it to a server that's already running:
tmux source-file ~/.tmux.conf
Example: a game server in tmux
Start a session, go to the server folder and launch the server. The example uses a Minecraft server; the installation is in our How to make a Minecraft server guide.
tmux new -s minecraft
cd /opt/minecraft
java -Xms2G -Xmx2G -jar server.jar nogui
When the server is up, detach with Ctrl + B, then d and close SSH. Later, log in and return to the live console:
tmux attach -t minecraft
Type stop in the console to shut the server down cleanly. You can also send a command or read the console without attaching, which is useful in scripts:
tmux send-keys -t minecraft 'say Restarting in 5 minutes' Enter
tmux capture-pane -p -t minecraft
You can also pass the command directly, as our Palworld server guide does with tmux new -s palworld ./PalServer.sh, but then the window closes as soon as the program exits and any error message is gone with it. While you're still testing, start a shell first and run the command inside it.
The same pattern works for any long task: a release upgrade (How to upgrade Ubuntu), a large transfer (How to use rsync) or a database import.
tmux vs screen, nohup and systemd
| Tool | Survives SSH closing | Return to the console | Restarts after a crash | Starts at boot |
|---|---|---|---|---|
nohup command & | Yes | No, output goes to a file | No | No |
screen | Yes | Yes | No | No |
tmux | Yes | Yes | No | No |
| systemd service | Yes | No, logs are in journalctl | Yes, with Restart= | Yes, with enable |
nohup is enough for a one-off command that needs no input; its output goes to nohup.out. screen does the same core job as tmux, so use whichever you know. tmux is not a process manager: it doesn't restart a program that crashed, and its sessions are gone after a reboot. For anything that has to run around the clock, such as a bot, an API or a production game server, create a service as described in our How to create a systemd service guide. Use tmux for interactive consoles, tests and long one-off jobs.
Shortcut table
Press Ctrl + B first, then the key:
| Key | What it does |
|---|---|
d | Detach from the session |
s | List sessions and switch between them |
$ | Rename the session |
c | New window |
n / p | Next / previous window |
0–9 | Go to the window with that number |
w | List windows |
, | Rename the window |
& | Close the window |
% | Split into left and right panes |
" | Split into top and bottom panes |
| Arrow keys | Move to the pane in that direction |
z | Zoom the pane, press again to restore |
x | Close the pane |
[ | Copy mode for scrolling, q to leave |
? | List all key bindings |
Common errors
no sessionsorno server running on ...: There is no session to attach to. It was never created, it ended when its last shell exited, or the server was rebooted. Sessions also belong to the user who started them: a session started as root is not visible to another user, and the other way round.can't find session: name: The name is wrong. Check it withtmux ls.duplicate session: name: A session with that name already exists. Attach to it withtmux attach -t nameor usetmux new -A -s name.sessions should be nested with care, unset $TMUX to force: You rantmux newortmux attachinside tmux. Switch sessions withCtrl + B, thensinstead, or create a second one in the background withtmux new -d -s name. Don't unset$TMUX; a tmux inside a tmux makes the shortcuts confusing.open terminal failed: missing or unsuitable terminal: xterm-kitty: The server doesn't know your terminal'sTERMvalue, which is common with newer terminal emulators. Start tmux withTERM=xterm-256color tmux attach -t name.open terminal failed: not a terminal: tmux was started without a terminal, for example withssh host tmux attach. Usessh -t user@host tmux attach -t name, and in scripts or cron start sessions withtmux new -d.- The session looks small or is still marked
(attached): An old connection is still attached.tmux attach -d -t nameattaches you and detaches the others.
tmux on Nodesty servers
Nodesty AMD Ryzen 9 9950X VPS and AMD EPYC 7763 VPS plans come with NVMe disks and full root access, so you can install tmux and keep game servers, upgrades and long transfers running after you close your terminal. Daily backups are free on VPS plans and are kept for 7 days.
Frequently Asked Questions
What is tmux used for?
tmux is a terminal multiplexer. It keeps your shell and the programs in it running on the server even when your SSH connection closes, and lets you come back to them later. It also lets you open several windows and split panes inside a single SSH connection.
How do I leave tmux without stopping my program?
Press Ctrl + B, release it, then press d. This detaches you from the session and the program keeps running in the background. Typing exit or pressing Ctrl + D instead closes the shell, and when the last shell closes the session ends.
Does a tmux session survive a server reboot?
No. tmux sessions live in memory, so a reboot or a shutdown ends all of them together with the programs inside. If a program has to come back by itself after a reboot, run it as a systemd service.
Should I run my game server in tmux or as a systemd service?
tmux is a good fit for the first start, for testing and for servers where you want to type into the console. It doesn't restart a crashed server and doesn't start anything at boot. For a server that has to stay online around the clock, a systemd service is the more reliable choice.
What is the difference between tmux and screen?
Both keep programs running after you disconnect and let you reattach later. screen is older and is still found on many systems, while tmux is more actively developed and makes windows, split panes and configuration easier. If you already know one of them, there is no need to switch.
How do I scroll up in tmux?
Press Ctrl + B and then the opening square bracket to enter copy mode, scroll with the arrow keys or Page Up and Page Down, and press q to leave. If you add set -g mouse on to your ~/.tmux.conf file, you can scroll with the mouse wheel as well.
About the author
Nodesty Team · Infrastructure & Support
The Nodesty team runs our servers, network and DDoS protection day to day and answers customer support requests around the clock. These guides come from that work.
Related articles

How to Install a LEMP Stack on Ubuntu and Debian
How to install a LEMP stack on Ubuntu and Debian: Nginx, MariaDB and PHP-FPM, the server block, the PHP socket, permissions, HTTPS and common errors.

How to Deploy a Node.js App with PM2 and Nginx
How to deploy a Node.js app on a Linux VPS: Node.js LTS, npm ci, PM2 with autostart and reload, an Nginx reverse proxy, HTTPS, updates and common errors.

How to Deploy a Python App with Gunicorn and Nginx
How to deploy a Python app (Flask or Django) on Linux: venv, Gunicorn, systemd, Nginx reverse proxy, static files, HTTPS, updates and common errors.