Use tmux for persistent sessions
When you close your SSH window, the shell goes with it, and any command still running is stopped. tmux is a terminal multiplexer that keeps your sessions alive on the server, so you can start a long job, disconnect, come back tomorrow, and pick up exactly where you left off.
Before you begin
- A VPS running Ubuntu 24.04 LTS and SSH access as a user with sudo rights, such as alex.
- A basic idea of the command line: running commands, and typing into a prompt.
Step 1: Install tmux
Update the package list so apt knows the latest versions, then install tmux. The -y flag answers "yes" to the install prompt.
sudo apt update
sudo apt install -y tmux
Confirm the install worked by checking the version:
tmux -V
tmux 3.4
Step 2: Start a named session
The new -s part creates a session with a name you choose, here work. You are now inside it, and it looks like an ordinary shell. Names make it easier to find the right session later.
tmux new -s work
Run something long inside it so you have a process to protect. The ping command with -c 1000 sends a thousand packets and then stops, which is plenty for a test.
ping -c 1000 example.com
Step 3: Detach and disconnect safely
To leave the session running without closing it, press Ctrl+b, release both keys, then press d for "detach". You return to your normal shell, and the session keeps running on the server. Now you can close your SSH window with a clear conscience.
[detached (from session work)]
Step 4: Reconnect and reattach
Log in again later and list the sessions that are still alive:
tmux ls
work: 1 windows (created Sat Oct 31 09:14:02 2026) [80x24] (attached)
Attach to it by name. You will see your ping still counting, exactly as you left it.
tmux attach -t work
Step 5: Use windows and panes
A session can hold several windows, like tabs, and each window can be split into panes. Every shortcut starts with the prefix, Ctrl+b, pressed first and then released before the next key.
- Ctrl+b c creates a new window.
- Ctrl+b n and Ctrl+b p move to the next and previous window.
- Ctrl+b % splits the window left and right. Ctrl+b " splits it top and bottom.
- Ctrl+b arrow key moves between panes.
- Ctrl+b [ enters scroll mode so you can read older output. Press q to leave it.
Step 6: Stop a session when you are finished
Type exit in each pane or window to close it. When the last one closes, the session ends. You can also end a session from outside it, by name:
tmux kill-session -t work
This stops every process in the session, including the one that is still running, so only use it when you are done.
deploy, logs, or backup. When you have several sessions, tmux ls becomes a quick map of your server's work.Troubleshooting
- "no server running on /tmp/tmux-1000/default". No tmux session exists at all. Either you already exited them all, or the server rebooted. Start a new one with
tmux new -s work. - "can't find session: work". The name is wrong. Run
tmux lsto see the exact names. - Ctrl+b does nothing. Your local terminal may be capturing the key combination. Try again in a different terminal app, or check that you are inside tmux and not in a plain shell.
- Sessions disappear after a reboot. tmux does not survive a reboot by default. Anything that must run after a reboot belongs in a systemd service, which is covered in the guide on systemd services.
Next steps
Try starting a long task such as a database backup or a file copy inside tmux, then detach and check on it the next day. For jobs that must run without anyone logged in, or should restart automatically, move them into a systemd service.
Something not working? Chat or email our support team and we will help you get unstuck.
Contact support