---
title: "tmux on a VPS: how to keep a process running after you close SSH | StreetHosting"
description: "Your process dies when SSH closes because of SIGHUP. Learn how to use tmux, screen and nohup to keep it alive, and when to replace them with a systemd service."
url: "https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh"
type: "page"
language: "en-US"
---

VPS · 7 min · Beginner

Published on Nov 13, 2026 · Updated on Nov 13, 2026

# How to keep a process running on your VPS after you close SSH

Closing the terminal kills whatever was running in it. tmux keeps the session alive on the server, and you come back to it whenever you want. See the steps, the alternatives and the point where a service is the right answer.

By [Equipe StreetHosting](https://streethosting.com.br/en/autores#equipe-streethosting) · StreetHosting infrastructure and support team

[Linux administration](https://streethosting.com.br/en/guides/topics/linux)

Summarize with:

[](https://chat.openai.com/?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Ftmux-keep-process-running-ssh.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "ChatGPT") [](https://claude.ai/new?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Ftmux-keep-process-running-ssh.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Claude") [](https://www.google.com/search?udm=50&aep=11&q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Ftmux-keep-process-running-ssh.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Google AI Mode") [](https://x.com/i/grok?text=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Ftmux-keep-process-running-ssh.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Grok") [](https://www.perplexity.ai/search/new?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Ftmux-keep-process-running-ssh.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Perplexity")

Share:

[](https://x.com/intent/tweet?text=tmux%20on%20a%20VPS%3A%20how%20to%20keep%20a%20process%20running%20after%20you%20close%20SSH&url=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Ftmux-keep-process-running-ssh "Share on X") [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Ftmux-keep-process-running-ssh "Share on Facebook") [](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Ftmux-keep-process-running-ssh "Share on LinkedIn") [](https://wa.me/?text=tmux%20on%20a%20VPS%3A%20how%20to%20keep%20a%20process%20running%20after%20you%20close%20SSH%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Ftmux-keep-process-running-ssh "Share on WhatsApp")

For agents: Copy as Markdown [.md](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh.md)

In this guide 6 sections

* [Why the process dies](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#por-que-morre)
* [tmux: sessions that survive](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#tmux)
* [Panes and windows](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#paineis)
* [screen and nohup](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#screen-nohup)
* [When to switch to a systemd service](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#systemd)
* [Where to run it](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#onde-rodar)

Quick answer

The process dies because Linux sends the SIGHUP signal to everything attached to the terminal when the SSH session closes. To avoid that, run the command inside tmux: use `tmux new -s nome` to create the session, leave it with `Ctrl+b` and then `d` and come back with `tmux attach -t nome`. For something that has to stay up permanently, the right tool is a systemd service.

## Why the process dies[](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#por-que-morre)

When you connect over SSH, the server opens a shell tied to your terminal. Everything you start from it is a child of that shell. When you close the window, lose your internet or run `exit`, the terminal goes away and the system sends the SIGHUP signal (hang up, as in putting down the phone) to the shell and its processes. Most programs read SIGHUP as an order to quit.

That is why the bot, the game server or the 40-minute script you left running is stopped when you come back. There are four ways to fix it, from the most practical for testing to the most correct for production:

| Tool            | What it is for                                                 | Comes back after a reboot |
| --------------- | -------------------------------------------------------------- | ------------------------- |
| tmux            | Interactive session you open and close whenever you want       | No                        |
| screen          | The same idea, in an older tool                                | No                        |
| nohup           | Runs a command in the background and ignores SIGHUP            | No                        |
| systemd service | Production application that starts at boot and restarts itself | Yes                       |

## tmux: sessions that survive[](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#tmux)

tmux is a terminal multiplexer. It runs as its own process on the server and keeps the session inside it. When SSH closes, tmux does not receive SIGHUP, because it is not tied to your terminal, and the session stays intact. On Ubuntu and Debian install it with `sudo apt install tmux`.

The basic flow takes four commands:

`# create a named session tmux new -s servidor # (inside the session: run your command as usual) # to leave without ending it: Ctrl+b, release, then press d # list the open sessions tmux ls # go back to a session tmux attach -t servidor # end a session for good, from outside it tmux kill-session -t servidor`

Every tmux shortcut starts with the `Ctrl+b` prefix: you press the two keys together, release them, and only then press the command key. The `d` stands for detach: you leave the session, but it keeps running.

1. Connect to the VPS over SSH and run `tmux new -s bot`.
2. Inside the session, start the program, for example `node index.js`.
3. Press `Ctrl+b`, release and press `d`. You are back at the normal shell and can close SSH.
4. Later, connect again and run `tmux attach -t bot`. The screen is exactly as you left it, with the accumulated output.

Give names that say what the session does, such as bot, build or backup. With several sessions open, `tmux ls` becomes a readable list instead of loose numbers.

## Panes and windows[](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#paineis)

tmux also splits the screen, which helps you follow one program's log while you work on another. All the shortcuts below apply after the `Ctrl+b` prefix:

* `%`: splits the screen into two panes side by side.
* `"` (double quote): splits into two panes, one above the other.
* **Arrow keys:** move focus between panes.
* `x`: closes the current pane, asking for confirmation.
* `c` creates a new window, and `n` and `p` move to the next and the previous one.
* `[`: enters scroll mode, to read the output that went by. Leave with `q`.

If you prefer to use the mouse to scroll and switch panes, create the file `~/.tmux.conf` with one line:

`set -g mouse on`

tmux reads this file when it starts. If a session is already open, apply the change right away with `tmux source-file ~/.tmux.conf`. A useful everyday layout is one pane with your program and another with `htop`, as the guide on [monitoring resources on your VPS](https://streethosting.com.br/en/guides/vps/monitor-vps-resources-htop-netdata) shows.

## screen and nohup[](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#screen-nohup)

If tmux is not installed and you would rather not install it, screen does the same basic job, in two lines:

`# create the session; to leave without ending it: Ctrl+a, release, then press d screen -S servidor # go back to it screen -r servidor`

nohup is something else: it does not create a session for you to come back to. It just runs the command ignoring SIGHUP and sends the output to a file. It suits a long task you do not need to watch live:

`# runs in the background, survives closing SSH nohup ./backup.sh > backup.log 2>&1 & # follow the output tail -f backup.log # find the process later pgrep -af backup.sh`

The `&` at the end puts the command in the background and `2>&1` merges the error output with the normal output into the same file. To stop the process, use `kill` with the number pgrep showed. Forgot nohup and the program is already running? Press `Ctrl+z`, run `bg` and then `disown` to detach it from the terminal. Still, tmux is far more comfortable for this case, because it lets you see the program again.

## When to switch to a systemd service[](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#systemd)

tmux, screen and nohup are great for one-off tasks: a database migration, a long build, a test of your bot. For anything that has to stay up every day, they have three limits:

* **Nothing restarts the process if it crashes.** The program fails, the tmux session sits there with the error on screen and the service stays down until you notice.
* **Nothing starts after a reboot.** A kernel update, maintenance or a power loss takes the session down and nobody recreates it.
* **The logs are scattered.** They depend on what is still on the tmux screen or on a file you created yourself.

The practical rule: if you open the session to see what is going on, use tmux. If the program has to work without you watching, make it a service. The guide on [how to create a systemd service](https://streethosting.com.br/en/guides/vps/create-systemd-service-linux) shows the full file, with automatic restart and logs in journalctl. If the app is Node, [PM2 with startup on systemd](https://streethosting.com.br/en/guides/vps/pm2-vs-systemd-nodejs) is another path.

Be careful not to leave the same program running twice: one inside a forgotten tmux session and another as a service. They fight over the same port and the service falls into a crash loop. Before migrating, enter the session with tmux attach, stop the program and end the session with `tmux kill-session -t nome`.

## Where to run it[](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#onde-rodar)

Everything here calls for a Linux server of your own, with a full shell and the freedom to install tmux and create services. On [StreetHosting VPS](https://streethosting.com.br/en/vps) you get root access on KVM, so you can use tmux for what is temporary and systemd for what is permanent. SSH access is explained in [how to access your VPS for the first time](https://streethosting.com.br/en/guides/vps/connect-to-vps-via-ssh-first-time).

The Xeon VPS starts at R$ 26.00 per month, with 2 vCPU, 2 GB of RAM and 20 GB of NVMe. All of them are in São Paulo, with AntiDDoS included, up to 5 TB of traffic per month and activation in about 60 seconds after Pix or card approval.

In this guide

* [Why the process dies](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#por-que-morre)
* [tmux: sessions that survive](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#tmux)
* [Panes and windows](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#paineis)
* [screen and nohup](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#screen-nohup)
* [When to switch to a systemd service](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#systemd)
* [Where to run it](https://streethosting.com.br/en/guides/vps/tmux-keep-process-running-ssh#onde-rodar)

## Frequently asked questions

Does tmux keep running if my internet drops?

Yes. The tmux session lives on the server, not on your computer. If the connection drops, SSH closes, but tmux and whatever is inside it keep running. Just connect again and use tmux attach.

Does tmux survive a VPS reboot?

No. When the server restarts, every process is ended, tmux included. For anything that has to come back on its own after a reboot, use a systemd service.

What is the difference between tmux and screen?

They do the same basic thing, which is keeping sessions alive after you disconnect. tmux is more modern, has easier split panes and simpler configuration. screen is older and shows up preinstalled on some systems.

How do I scroll up inside tmux?

Press Ctrl+b and then the \[ key to enter scroll mode. Use the arrow keys, PageUp and PageDown to move and q to leave. You can also turn the mouse on with set -g mouse on in the \~/.tmux.conf file.

Can I run my bot or my site with tmux alone?

You can for testing, but it is not ideal for production. If the process crashes nobody restarts it, and after a reboot it does not come back. A systemd service solves both.

Next step

See VPS plans

Root VPS in Brazil with NVMe and Anti-DDoS.

[See VPS plans](https://streethosting.com.br/en/vps)

## Related guides

[VPS Intermediate How to create a systemd service on Linux to run any app A systemd service starts your app with the server, restarts it when it crashes and keeps its logs. See the full .service file, the daily commands and the errors that trip up most first timers. 9 min Read guide](https://streethosting.com.br/en/guides/vps/create-systemd-service-linux) [VPS Intermediate PM2 vs systemd: keep your Node app always online on a VPS Your app needs to come back on its own after a crash and start together with the VPS. PM2 and systemd solve this in different ways. Here is how to set up each one and which to pick. 3 min Read guide](https://streethosting.com.br/en/guides/vps/pm2-vs-systemd-nodejs) [VPS Beginner How to connect to your VPS for the first time via SSH You bought the VPS and received an IP, a user and a password. Now it is time for the first login. Here is how to connect over SSH from any system and what to do in the first few minutes. 3 min Read guide](https://streethosting.com.br/en/guides/vps/connect-to-vps-via-ssh-first-time)

[← Back to the Guide Center](https://streethosting.com.br/en/guides)
