> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Keep a Process Running After SSH Disconnects (tmux)

> Keep a process running after SSH disconnects: start tmux new -s work, run your command, press Ctrl+b then d to detach, and reconnect later with tmux attach -t work.

To keep a process running after SSH disconnects, start it inside tmux. Run `tmux new -s work`, start your command, then press **Ctrl+b** followed by **d** to detach. The command keeps running on the server after you log out. Reconnect later with `tmux attach -t work`. GNU screen works the same way with `screen -S work`, **Ctrl+a** then **d**, and `screen -r work`.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5 minutes | Ubuntu, Debian, AlmaLinux, Rocky Linux and most other distributions | SSH access |

## Before you start

* Normally, every program you start in an SSH session stops when the connection drops. tmux and screen are "terminal multiplexers": they keep a session alive on the server, independent of your connection.
* Use them for long jobs (updates, large copies, compiling, a game server console) and to survive flaky Wi-Fi.
* For services that must run permanently and restart after a reboot, use a [systemd service](https://help.freakhosting.com/portals/other/how-to-create-a-systemd-service.md) instead.

## Should I use tmux or screen?

Use **tmux** on new servers. It is in the main repositories of every distribution we cover. **screen** is older and still widespread; on AlmaLinux and Rocky Linux 9 and 10 it is only available from the EPEL repository.

| | tmux | screen |
| - | - | - |
| Start a named session | `tmux new -s work` | `screen -S work` |
| Detach | **Ctrl+b**, then **d** | **Ctrl+a**, then **d** |
| List sessions | `tmux ls` | `screen -ls` |
| Reattach | `tmux attach -t work` | `screen -r work` |
| End a session | `exit` inside it, or `tmux kill-session -t work` | `exit` inside it, or `screen -S work -X quit` |

## How to install tmux

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> sudo apt update
> sudo apt install tmux
> ```

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo dnf install tmux
> ```

It may already be installed: `tmux -V` prints the version if it is.

## How to keep a command running with tmux

**1. Start a named session**

```bash theme={null}
tmux new -s work
```

A green status bar appears at the bottom. You are now inside tmux.

**2. Run your command**

Start the long job as usual, for example:

```bash theme={null}
rsync -avP /var/www/ /backup/www/
```

**3. Detach**

Press **Ctrl+b**, let go, then press **d**. You return to your normal shell and see `[detached (from session work)]`. You can now close SSH.

**4. Reattach later**

Log in again and run:

```bash theme={null}
tmux attach -t work
```

You are back in the session, with the command still running and all its output.

## Useful tmux keys

All shortcuts start with the prefix **Ctrl+b**. Press it, release, then press the next key.

| Keys | What it does |
| - | - |
| **Ctrl+b** **d** | Detach from the session |
| **Ctrl+b** **c** | New window |
| **Ctrl+b** **n** / **p** | Next / previous window |
| **Ctrl+b** **%** | Split the pane left and right |
| **Ctrl+b** **"** | Split the pane top and bottom |
| **Ctrl+b** **\[** | Scroll mode (use arrow keys, **q** to leave) |

## How to use screen instead

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> sudo apt install screen
> ```

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo dnf install epel-release
> sudo dnf install screen
> ```

```bash theme={null}
screen -S work          # start a named session
# run your command, then press Ctrl+a followed by d to detach
screen -ls              # list sessions
screen -r work          # reattach
```

## How to check it worked

After detaching, list the sessions:

```bash theme={null}
tmux ls
```

```text theme={null}
work: 1 windows (created Wed Nov  4 13:25:37 2026)
```

For screen:

```bash theme={null}
screen -ls
```

```text theme={null}
There is a screen on:
	22673.work	(11/04/26 13:25:37)	(Detached)
1 Socket in /run/screen/S-alex.
```

## Frequently asked questions

### Does tmux survive a server reboot?

No. A reboot ends every tmux and screen session and the programs in them. Use a [systemd service](https://help.freakhosting.com/portals/other/how-to-create-a-systemd-service.md) for anything that must start on boot.

### What about nohup or the & sign?

`nohup command &` keeps a single command running after logout and writes its output to `nohup.out`, but you can't get back to it interactively. tmux lets you reattach and type into it.

### I get "sessions should be nested with care". What does it mean?

You ran `tmux` inside an existing tmux session. Detach first, or attach to the session you already have with `tmux attach`.

### Can two people share one tmux session?

Yes, if they log in as the same user: both run `tmux attach -t work` and see the same screen. This is handy for supporting someone remotely.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [SSH into a server](https://help.freakhosting.com/portals/other/how-to-connect-to-a-linux-server-with-ssh.md)
>
> Connect before you start tmux.

> [card] [Create a systemd service](https://help.freakhosting.com/portals/other/how-to-create-a-systemd-service.md)
>
> Run programs permanently.

> [card] [SSH config shortcuts](https://help.freakhosting.com/portals/other/how-to-use-ssh-config-file-shortcuts.md)
>
> Keep idle SSH sessions alive.

> [card] [Essential Linux commands](https://help.freakhosting.com/portals/other/essential-linux-commands-for-server-beginners.md)
>
> The basics for new admins.

***

> [!NOTE]
>
> **Checked against the official [tmux manual](https://man.openbsd.org/tmux) and [GNU Screen manual](https://www.gnu.org/software/screen/manual/screen.html)** on 4 November 2026; sessions, detach keys and `ls` output were tested with tmux 3.4 and screen 4.09 on Ubuntu 24.04 LTS. EPEL package availability checked on [Fedora Packages](https://packages.fedoraproject.org/pkgs/screen/screen/).

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.