How to keep a Linux VPS command running with screen or tmux

Print
  • 0

Long-running commands stop if your SSH session closes unless they are managed by a service or terminal multiplexer. screen and tmux let you detach from a command and reconnect later.

This is useful for temporary tasks, test servers, console-only installers, and one-off maintenance. For production game servers, a proper systemd service is usually better.

 

Install screen or tmux

On Ubuntu or Debian:

sudo apt update
sudo apt install screen tmux

On AlmaLinux, Rocky Linux, Oracle Linux, or CentOS:

sudo dnf install screen tmux

If dnf is not available on an older image, use yum instead.

 

Using screen

  1. Create a named session:
screen -S gameserver
  1. Start your command inside the screen session.
  2. Detach with CTRL + A, then D.
  3. List sessions:
screen -ls
  1. Reconnect later:
screen -r gameserver

Linux VPS terminal showing a detached screen session and reconnect command

 

Using tmux

tmux new -s gameserver

Detach with CTRL + B, then D. Reconnect with:

tmux attach -t gameserver

 

Useful session commands

CommandUse
screen -lsList screen sessions.
screen -r nameReconnect to a screen session.
tmux lsList tmux sessions.
tmux attach -t nameReconnect to a tmux session.

 

When not to use screen or tmux

If the command needs to start automatically after a reboot, use a systemd service instead. For Minecraft, use How to run a Minecraft server as a systemd service on a Linux VPS.


Was this answer helpful?

Related Articles

« Back

Follow us on Social Media

Stay in the loop! Follow our social media accounts and stay up-to-date with the latest news, announcements, tips & tricks and behind-the-scenes insights!