How to Run a Telegram Bot 24/7 on a VPS (Python + systemd)
A bot on your laptop dies when the lid closes. Here is how to run it on a VPS so it stays online, restarts itself after a crash or reboot, and costs $10 a month.
To keep a Telegram bot online around the clock, put it on a VPS and run it as a systemd service. systemd starts the bot at boot and restarts it within seconds if it crashes. This guide takes you from an empty server to a running Python bot in about ten minutes, with the exact commands.
Why a VPS and not your laptop
- Always on — a laptop sleeps, loses Wi-Fi and reboots for updates; a server does none of that.
- Restarts itself — systemd brings the bot back after a crash or a reboot without you touching anything.
- Cheap — a polling bot uses very little CPU and RAM, so the smallest plan is enough.
Rule of thumb: a bot that polls Telegram for updates runs fine on 1 vCPU and 1 GB of RAM. Neckrez's Quark plan (1 vCPU, 1 GB, $10 a month) fits. Move up to Ion only if the bot keeps a large database or runs heavy tasks.
How to do it on Neckrez
- 1. Sign up with an email — no KYC, no card, no phone number.
- 2. Top up the balance in crypto — from $15. USDT on BEP20, TON, Polygon or Solana costs only cents in network fees.
- 3. Deploy a server — pick Ubuntu, any location close to you, and the Quark plan.
- 4. Wait about a minute — you get a dedicated IPv4 address and full root access.
- 5. Pay by the hour — billing runs only while the server exists, so you can test and destroy it whenever you like.
More on this use case on the VPS for bots page.
Prepare the server
Connect as root with the IP address from your dashboard, update the system and create a separate user for the bot. Running the bot as root is a bad idea: if the bot is compromised, so is the whole server.
ssh root@YOUR_SERVER_IP
apt update && apt upgrade -y
apt install -y python3 python3-venv ufw
adduser --disabled-password --gecos "" botuserInstall the bot
Switch to the new user, create a virtual environment so the bot's libraries stay separate from the system, and install the Telegram library.
su - botuser
mkdir -p ~/bot && cd ~/bot
python3 -m venv venv
./venv/bin/pip install python-telegram-botSave a minimal bot as bot.py in that folder. It answers /start, which is enough to prove everything works. Replace it with your own code later.
import os
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("The bot is running 24/7")
app = ApplicationBuilder().token(os.environ["BOT_TOKEN"]).build()
app.add_handler(CommandHandler("start", start))
app.run_polling()Keep the bot token out of the code. Put it in a file only the bot user can read:
echo 'BOT_TOKEN=PASTE_YOUR_TOKEN_FROM_BOTFATHER' > ~/bot/.env
chmod 600 ~/bot/.env
exitRun it as a systemd service
Back as root, create the service file. Restart=always is the line that keeps the bot alive.
nano /etc/systemd/system/bot.service[Unit]
Description=Telegram bot
After=network-online.target
Wants=network-online.target
[Service]
User=botuser
WorkingDirectory=/home/botuser/bot
EnvironmentFile=/home/botuser/bot/.env
ExecStart=/home/botuser/bot/venv/bin/python bot.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targetEnable it so it starts at every boot, start it now, and check that it runs:
systemctl daemon-reload
systemctl enable --now bot
systemctl status bot
journalctl -u bot -fSend /start to your bot in Telegram. It should reply. Press Ctrl+C to leave the log view. After you change the code, apply it with systemctl restart bot.
Lock the server down
A polling bot makes outgoing connections only, so nothing needs to be open except SSH:
ufw allow OpenSSH
ufw enableOne honest caveat: this guide uses polling, which is the simplest way. Webhooks are faster to react but need a domain name and HTTPS, so start with polling and switch only if you need to.
Features that help a bot server
- Hourly billing — spin up a second server to test a risky change, then destroy it and pay for a few hours only.
- Snapshots — take a backup before a big update; you can restore it onto a new server later (kept 7 days).
- Instant IP swap — on Vultr servers, if an address ends up on a blocklist you can change it without rebuilding the server.
- Free anti-DDoS on every plan.
FAQ
Do I need a domain name? No. A bot that polls Telegram needs only the server's IP address.
Will the bot start again after a reboot? Yes. systemctl enable starts it at boot, and Restart=always brings it back after a crash.
How much does it cost to run? The Quark plan is $10 a month, billed by the hour, and you can pay with crypto.
Get started
Plans start at $10 a month, billed by the hour. Deploy a server and run your bot.