Create new user
Replace 'alex' with the desired username.
adduser alex # Change 'alex' to your name
usermod -aG sudo alexGuide for the secure installation and maintenance of OpenClaw (Clawdbot) on a hardened VPS.
Recommended procedure: system hardening, non-root user, firewall, key-based SSH, private perimeter (Tailscale), service persistence and automatic security updates.
⚠️ Execute the steps in the given order to avoid locking yourself out of the server.
Create a non-root user before hardening access.
Replace 'alex' with the desired username.
adduser alex # Change 'alex' to your name
usermod -aG sudo alexRun from your local machine.
ssh-copy-id alex@YOUR_SERVER_IPDo not continue if the connection fails.
ssh alex@YOUR_SERVER_IPFirewall, automatic updates and SSH restriction.
sudo apt update && sudo apt upgrade -y
sudo apt install unattended-upgrades fail2ban -y
sudo dpkg-reconfigure -plow unattended-upgradessudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw enablesudo nano /etc/ssh/sshd_config
# After editing the directives below, restart the service:
sudo systemctl restart sshLocate and set the following directives:
PasswordAuthentication noPermitRootLogin noPubkeyAuthentication yesRestrict the server to the Tailscale private network.
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up# Allow traffic from Tailscale internal subnet
sudo ufw allow from 100.64.0.0/10 to any port 22 proto tcp
# Remove the rule that opened SSH to the whole world
sudo ufw delete allow sshBot installation, credential permissions and PM2 automatic startup.
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
sudo npm install -g pm2npm install -g clawdbot
clawdbot doctorchmod 700 ~/.clawdbot/credentials
chmod 600 .env # If using env filepm2 start clawdbot --name "ai-bot"
pm2 save
pm2 startup
# (Copy and paste the command the terminal returns)Verify hardening and exposed ports.
clawdbot security audit --deepIn the "Local Address" column, 0.0.0.0 (public) should not appear on sensitive ports except SSH if phase 3 has not yet been applied.
sudo ufw status verbose
ss -tulnp | grep LISTENKey-based access: exclusive access via private SSH key.
Private perimeter: server does not respond to external pings (outside Tailscale).
Updates and resilience: automatic patches and service restart on failure.
Least privilege: credentials and sensitive files with restricted permissions.