Independent Field Manual — Not affiliated with, endorsed by, or operated by OpenClaw
Navigation

install vps

Run OpenClaw After SSH Logout (PM2)

How to use PM2 to keep your OpenClaw Gateway running 24/7 in the background after you close your laptop or disconnect from the VPS.

Read in Hinglish
Difficulty
beginner
Duration
10 minutes
Tested On
Ubuntu 24.04 LTS with Node.js v20+
Access Mode
SSH
Pre-flight status
Pre-Flight Approved
Risk low
Gateway Private
On this page
Safe guide Standard background process management. Safe to run as your non-root user.

Short answer

If you start OpenClaw using npx openclaw start and then close your terminal, the process dies. To keep it running permanently, install a process manager called PM2.

Why processes stop after logout

When you connect to your VPS via SSH, Linux starts a new “session.” Any program you start in the terminal (like npx openclaw start) is attached to that session. When you disconnect or close your laptop, Linux ends the session and kills all attached programs.

To prevent this, you need a process manager. It runs in the background (as a “daemon”), detaches your programs from the SSH session, and restarts them automatically if they crash.

For Node.js applications like OpenClaw, PM2 is the industry standard. (Systemd is also an option, but PM2 is much easier for beginners and handles Node logs gracefully).

Step 1: Install PM2

First, stop your currently running Gateway if it is running in your terminal (Ctrl+C).

Next, install PM2 globally using npm:

bash
npm install -g pm2

Depending on how you installed Node.js, you might need to run this without sudo. If you followed our nvm guide, do NOT use sudo.

Verify PM2 is installed:

bash
pm2 -v

Step 2: Start the Gateway with PM2

Navigate to your OpenClaw workspace directory (where your .env and database.sqlite live):

bash
cd ~/openclaw-workspace

Start the OpenClaw Gateway using PM2. We will name the process “openclaw” to make it easy to remember:

bash
pm2 start npx --name openclaw -- openclaw start

The '--' is important. It tells PM2 to pass the 'openclaw start' arguments to npx.

You should see a table appear showing the process status:

[PM2] Starting /home/clawuser/.nvm/.../bin/npx in fork_mode\n...\n│ id │ name      │ status │ restart │ uptime │ cpu │ mem      │\n│ 0  │ openclaw  │ online │ 0       │ 0s     │ 0%  │ 25.0 MB  │

Step 3: Enable startup persistence (Reboot survival)

Right now, PM2 keeps OpenClaw running when you close your laptop. But if the VPS itself restarts (e.g., your hosting provider performs maintenance), PM2 will not start automatically.

To make PM2 start on server boot, run:

bash
pm2 startup

PM2 will print a command that looks something like this: sudo env PATH=$PATH:/home/clawuser/.nvm/... pm2 startup systemd -u clawuser --hp /home/clawuser

Copy the command PM2 gives you, and run it in your terminal.

Finally, save the current PM2 process list so it remembers to start OpenClaw:

bash
pm2 save

Step 4: The Reboot Test

The best way to know if your setup is robust is to test it.

  1. Reboot your server:
    bash
    sudo reboot
  2. Wait 2 minutes for the server to come back online.
  3. SSH back into your server.
  4. Check PM2 status:
    bash
    pm2 status

If OpenClaw shows as online, your setup is complete. It will run 24/7.

Essential PM2 commands

You will use these commands frequently when managing your Gateway.

TaskCommand
View status of all appspm2 status
View live logspm2 logs openclaw
Restart the Gatewaypm2 restart openclaw
Stop the Gatewaypm2 stop openclaw
View detailed app infopm2 show openclaw

Log inspection

Because the Gateway is running in the background, you will not see errors printed to your screen automatically. If your bot stops replying, your first step should always be checking the logs:

bash
pm2 logs openclaw --lines 50

This shows the last 50 lines of logs and then watches for new ones. Press Ctrl+C to exit log view.

Rollback: How to remove the PM2 process

If you want to stop running OpenClaw in the background and return to manual starts:

  1. Stop the process:
    bash
    pm2 stop openclaw
  2. Delete it from PM2’s list:
    bash
    pm2 delete openclaw
  3. Save the empty list so it doesn’t try to start on reboot:
    bash
    pm2 save --force

What not to do

  • Do not run PM2 as root. Always run it as your normal user. Running PM2 as root means OpenClaw runs as root, which is a massive security risk.
  • Do not use screen or tmux instead of PM2. While those tools keep the session alive, they do not automatically restart the Gateway if it crashes, nor do they handle server reboots cleanly. Use PM2.

ClawReady.in is an independent educational resource and setup service. It is not affiliated with, endorsed by, or operated by OpenClaw.