I Control My Server from Telegram with AI — OpenClaw Setup Guide

Watch the Full Tutorial
If you run a VPS, you know the drill. Something feels off, you open a terminal, SSH in, try to remember the right command, check the logs, restart a service. And if you're on your phone? Forget it.
What if you could just text your server and ask it what's going on — in plain English? That's exactly what we're building today with OpenClaw, a free, open-source AI agent that lives on your server and talks to you through Telegram.
What You'll Build
By the end of this guide, you'll have an AI agent on your server that you can message from Telegram to:
- Check if your website is up and healthy
- Monitor disk space, CPU, and memory usage
- Read and summarize nginx access logs
- Restart services like nginx or your Node.js app
- Edit source code and deploy changes — all from one message
- Diagnose performance issues with AI-powered analysis
The Architecture
The setup uses two VPS instances on Hetzner:
[VPS 1: Website] <--- SSH ---> [VPS 2: OpenClaw + Telegram]
nginx AI Agent
Next.js app Controls VPS 1
VPS 1 runs your website (a Next.js app behind nginx). VPS 2 runs OpenClaw, which connects to Telegram and has SSH access to VPS 1. This separation keeps your website server clean — OpenClaw runs elsewhere and reaches in via SSH when needed.
Step 1: Create a Dedicated User
SSH into your second VPS (the one that will run OpenClaw). Create a dedicated user — don't run this as root:
adduser openclaw
usermod -aG sudo openclaw
loginctl enable-linger openclaw
The loginctl enable-linger command is needed on headless servers so the background service works even when nobody is logged in.
Switch to the new user:
su - openclaw
Step 2: Install OpenClaw
One command installs everything — Node.js, dependencies, and OpenClaw itself:
curl -fsSL https://openclaw.ai/install.sh | bash
The installer starts the onboarding process automatically. You'll need to:
- Connect your LLM: Select OpenRouter, enter your API key, and choose a model (DeepSeek V3.2 works well and is affordable)
- Connect Telegram: Get a bot token from BotFather — takes about 30 seconds
- Search provider: Keep the default (DuckDuckGo Search)
Step 3: Set Up the Background Service
After onboarding, set up the environment variables and gateway service so OpenClaw stays running:
source ~/.bashrc
mkdir -p /run/user/$(id -u)
echo 'export XDG_RUNTIME_DIR=/run/user/$(id -u)' >> ~/.bashrc
echo 'export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus"' >> ~/.bashrc
source ~/.bashrc
openclaw gateway install --force
systemctl --user daemon-reload
systemctl --user start openclaw-gateway.service
systemctl --user enable openclaw-gateway.service
Verify it's running:
openclaw gateway status
You should see "Runtime: running" and "RPC probe: ok". The gateway survives reboots too.
Step 4: Set Up SSH Access to Your Website Server
Generate an SSH key and copy it to VPS 1 (your website server):
ssh-keygen -t ed25519
ssh-copy-id root@YOUR_WEBSITE_SERVER_IP
Quick test to make sure it works:
ssh root@YOUR_WEBSITE_SERVER_IP "echo 'connection works'"
Step 5: Pair with Telegram
Open your bot in Telegram and send it a message. First time, it asks you to pair — it gives you a code. Approve it from the server:
openclaw pairing approve telegram YOUR_CODE
This is a security feature — only you can talk to your bot.
Step 6: Give OpenClaw Context
The more context you give OpenClaw upfront, the better it performs. One detailed message saves you ten minutes of back-and-forth. Send something like this in Telegram:
"My website server is at [IP], SSH user is root. It runs a Next.js app located at /var/www/mysite, served by nginx as a reverse proxy to port 3000. The app is managed by a systemd service called 'nextjs'. To deploy changes: edit files, run 'npm run build', then restart with 'systemctl restart nextjs'. Remember all of this."
OpenClaw has persistent memory — it remembers this from now on.
What It Can Do
Here's what I demonstrated in the video:
Health Check
Me: "Is my site up?"
OpenClaw: SSHed in, curled the site, and reported it's healthy with response time.
Disk Space
Me: "How much disk space is left?"
OpenClaw: Ran the command and gave a human-readable summary — not raw terminal output.
Log Analysis
Me: "Show me what's in my nginx access log from the last hour"
OpenClaw: Summarized the traffic — how many requests, which pages were hit, unusual patterns. That's the difference between a script and an AI agent.
Service Restart
Me: "Restart nginx"
OpenClaw: "Done. nginx restarted successfully."
Code Changes + Deploy
Me: "Change the heading on my website to 'Powered by AI' and make it live"
OpenClaw: Edited the source code, rebuilt the app, and restarted the service — all from one Telegram message.
AI Diagnosis
Me: "My site feels slow today. Can you figure out what's going on?"
OpenClaw: Checked CPU, memory, disk, nginx, and response time — then gave a full diagnosis. A script can't think. This can.
Accessing the Dashboard
OpenClaw has a web dashboard where you can see live command execution. Create an SSH tunnel from your local machine:
ssh -N -L 18789:127.0.0.1:18789 openclaw@YOUR_OPENCLAW_SERVER_IP
Then open http://localhost:18789 in your browser. Select the Telegram session in the sidebar to watch commands execute in real time.
Why Not Just Use a Bash Script?
A script runs one command. OpenClaw thinks. When you say "my site feels slow," it doesn't just run top — it checks CPU, memory, disk, nginx config, response times, and synthesizes a diagnosis. It understands context, remembers your server setup, and gives you human-readable answers instead of raw terminal output.
What's Next
OpenClaw is free, open-source, and runs on any server. You can connect it to Telegram, Discord, WhatsApp, or whatever you use.
In the next video, I'll set it up to automatically monitor GitHub repos and alert me when something happens.