1.7 C
New York

How to Install and Set Up OpenClaw on a VPS: Complete Step-by-Step Guide (Ubuntu 24.04)

admin
adminhttps://linhbadien.com
Linh is an IT enthusiast and digital entrepreneur who shares practical insights about technology, SEO, affiliate marketing, and online income strategies on LinhBaDien.com. He focuses on creating transparent, actionable, and beginner-friendly content to help readers build sustainable online projects.

Published:

OpenClaw is a powerful open-source AI assistant (formerly known as Moltbot/Clawdbot) that runs autonomously on your server, automates tasks, and connects via messaging apps like WhatsApp or Telegram. This guide shows you how to install OpenClaw on a VPS, set up the gateway for 24/7 operation, create a secure SSH tunnel, and run it as a systemd service.

I. What You Need to Prepare Before Starting

Before you begin your OpenClaw VPS setup, make sure you have the following ready:

  • A VPS (Virtual Private Server) — Recommended providers: Hostinger VPS, or reliable Vietnamese hosts like AZDIGI, Vietnix, or Tinohost.
  • Operating System: Ubuntu 24.04 LTS (select this during VPS creation).
  • Your server’s public IP address (provided by your VPS host after setup).
  • A terminal application: Terminal (on macOS), PowerShell, or Command Prompt (on Windows).

💡 Quick Tip: Replace YOUR_SERVER_IP everywhere in this guide with your actual server IP (e.g., 143.198.45.123).

II. Connect to Your Server

This step lets you remotely access your VPS to start the OpenClaw installation.

Run the following SSH command in your local terminal:

Bash

ssh root@YOUR_SERVER_IP
  • You’ll be prompted for the root password.
  • Type the password (characters won’t appear on screen — this is normal) and press Enter.

III. Create a New User (Security Best Practice)

Never run everything as root. Instead, create a dedicated user called molt for better security.

  1. Create the user:Bashadduser molt
    • Set a strong password and fill in optional fields (or press Enter to skip).
  2. Grant sudo privileges:Bashusermod -aG sudo molt
  3. Switch to the new user:Bashsu - moltYou are now operating as user molt.

IV. Install OpenClaw

Install the OpenClaw self-hosted AI assistant by running the official installer script:

Bash

curl -fsSL https://openclaw.bot/install.sh | bash

Follow any on-screen prompts to complete the initial setup.

V. Start the OpenClaw Gateway

The gateway enables OpenClaw to communicate with your AI models and messaging apps.

Option A: Run with sudo (if needed)

Bash

sudo -u molt openclaw gateway --bind loopback --port 18789 --verbose

Option B: Run without sudo (if already logged in as molt):

First check your current user:

Bash

whoami

If it shows molt, run:

Bash

openclaw gateway --port 18789 --verbose

VI. Connect from Your Personal Computer (Secure SSH Tunnel)

To access the OpenClaw gateway securely from your local machine:

  1. Open a new Terminal/PowerShell window on your local computer (not the server).
  2. Run this command and keep the window open:

Bash

ssh -N -L 18789:127.0.0.1:18789 molt@YOUR_SERVER_IP

This creates a secure tunnel so your local machine can reach the gateway at localhost:18789.

By default, OpenClaw stops when you close the terminal. Use systemd to make it run persistently, even after reboots.

Why Find the Binary Path?

Systemd requires the full absolute path to the openclaw binary in ExecStart (it doesn’t search $PATH like your shell does). This prevents “command not found” errors.

Find the path (as user molt):

Bash

which openclaw

Typical result:

text

/home/molt/.npm-global/bin/openclaw

Use this full path in the service file below.

Create the Systemd Service File

  1. Create/edit the service file:Bashsudo nano /etc/systemd/system/openclaw-gateway.service
  2. Paste the following configuration (replace the ExecStart path if yours is different):

ini

[Unit]
Description=OpenClaw Gateway Service (24/7 AI Assistant)
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=molt
WorkingDirectory=/home/molt
Environment=PATH=/home/molt/.npm-global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ExecStart=/home/molt/.npm-global/bin/openclaw gateway --bind loopback --port 18789 --verbose
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=10

# Security hardening
NoNewPrivileges=yes
PrivateTmp=yes
ProtectSystem=strict
ProtectHome=read-only
ReadWritePaths=/home/molt/.openclaw
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
  1. Save and exit: Ctrl + X → Y → Enter.
  2. Activate and start the service:Bashsudo systemctl daemon-reload sudo systemctl enable openclaw-gateway sudo systemctl start openclaw-gateway
  3. Check status (look for “active (running)” in green):Bashsudo systemctl status openclaw-gateway.service

VIII. Troubleshooting Common Issues

If something goes wrong during your OpenClaw setup on VPS:

  • Run diagnostics:Bashopenclaw doctor
  • Auto-repair detected issues:Bashopenclaw doctor --repair
  • Restart the service:Bashsudo systemctl restart openclaw-gateway.service
  • View live logs:Bashsudo journalctl -u openclaw-gateway.service -f
  • Stop the service (if needed):Bashsudo systemctl stop openclaw-gateway.service

Note: Every server setup varies slightly. For specific errors, search the exact message on Perplexity AI, ChatGPT, or OpenClaw’s GitHub/community.

IX. Quick Reference Table – OpenClaw Commands Cheat Sheet

TaskCommand
Connect to serverssh root@YOUR_SERVER_IP
Switch to molt usersu – molt
Install OpenClaw`curl -fsSL https://openclaw.bot/install.sh
Start gateway manuallyopenclaw gateway –port 18789 –verbose
Create SSH tunnel (from local PC)ssh -N -L 18789:127.0.0.1:18789 molt@YOUR_SERVER_IP
Check service statussudo systemctl status openclaw-gateway.service
Run diagnosticsopenclaw doctor
Auto-repair issuesopenclaw doctor –repair

Follow this guide carefully and you’ll have your own self-hosted OpenClaw AI assistant running securely and reliably on a VPS. Enjoy automating tasks 24/7! If you run into issues, feel free to share error messages for more help.

Catalog

Recent articles