natbox.io

Blog / tmux

Keep commands running after you disconnect, with tmux

5 November 2026 · Tutorial · By Mohammad AlSaraf

You start a big download or a backup over SSH, your Wi-Fi drops, and the command dies with your connection. tmux fixes that: it keeps a terminal running on the server, so you can disconnect, go home, and pick it up again later exactly where it was.

About 5 minutes. Works on any natbox plan. Commands for Debian and Ubuntu; on AlmaLinux use dnf install -y tmux, on Alpine apk add tmux.

1. Install tmux and start a session

Log in to your server (ssh root@natbox.io -p YOUR_PORT), install tmux and start a session with a name you will remember:

apt install -y tmux
tmux new -s download
Installing tmux and starting a session called download

2. Run your long command inside it

You are now inside tmux: it looks like a normal terminal, with a green bar at the bottom showing the session name. Start anything that takes a while. Here we download a 756 MB Debian image:

A curl download running inside a tmux session called download, with the green tmux status bar at the bottom
The green bar shows you are inside tmux: session download, window 0.

3. Detach, and log out if you like

Press Ctrl+B, let go, then press D. You are back in your normal shell, and tmux tells you the session is still alive. tmux ls lists your sessions. You can now close the window, log out, or lose your connection: the command keeps running on the server.

Detaching from tmux and listing sessions with tmux ls

4. Come back to it

Log in again, from any computer, and reattach:

tmux attach -t download

Everything is where you left it. Our download had kept going and was at 94%:

After reattaching, the download is at 94 percent

When the command has finished, type exit to close the session.

5. Bonus: two panes side by side

Inside tmux, Ctrl+B then % splits the window in two. Here the left pane follows an app's log with journalctl -fu myapp while the right pane checks memory and disk. Ctrl+B then an arrow key moves between panes.

A tmux window split into two panes: an app log on the left, memory and disk checks on the right

The keys you need

tmux or a service?

tmux is for jobs you start by hand and want to watch: downloads, backups, updates, a game server console. Anything that should run all the time and start again after a reboot, such as a bot or a website, belongs in a systemd service instead: see Keep an app running. A tmux session does not survive a server restart.

No server yet? Try one free for a month.

Get new tutorials in Telegram. Follow @natboxio: every new post, plus short server tips.

More from the blog: What's new at natbox: Telegram bot, snapshots, keeping your trial and CaptchaBox, Welcome to the natbox blog, and our new video library. RSS feed.