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.
- Create the user:Bash
adduser molt- Set a strong password and fill in optional fields (or press Enter to skip).
- Grant sudo privileges:Bash
usermod -aG sudo molt - Switch to the new user:Bash
su - 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:
- Open a new Terminal/PowerShell window on your local computer (not the server).
- 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.
VII. Set Up OpenClaw to Run Automatically (Recommended – 24/7 Operation)
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
- Create/edit the service file:Bash
sudo nano /etc/systemd/system/openclaw-gateway.service - 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
- Save and exit: Ctrl + X → Y → Enter.
- Activate and start the service:Bash
sudo systemctl daemon-reload sudo systemctl enable openclaw-gateway sudo systemctl start openclaw-gateway - Check status (look for “active (running)” in green):Bash
sudo systemctl status openclaw-gateway.service
VIII. Troubleshooting Common Issues
If something goes wrong during your OpenClaw setup on VPS:
- Run diagnostics:Bash
openclaw doctor - Auto-repair detected issues:Bash
openclaw doctor --repair - Restart the service:Bash
sudo systemctl restart openclaw-gateway.service - View live logs:Bash
sudo journalctl -u openclaw-gateway.service -f - Stop the service (if needed):Bash
sudo 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
| Task | Command |
|---|---|
| Connect to server | ssh root@YOUR_SERVER_IP |
| Switch to molt user | su – molt |
| Install OpenClaw | `curl -fsSL https://openclaw.bot/install.sh |
| Start gateway manually | openclaw 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 status | sudo systemctl status openclaw-gateway.service |
| Run diagnostics | openclaw doctor |
| Auto-repair issues | openclaw 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.