Short answer: to keep a Telegram bot online 24/7, run it on a small Linux VPS as a systemd service. With long polling (the default in aiogram, python-telegram-bot, grammY and telegraf) the bot needs no domain, no certificate and no open port. A server with 1 vCPU and 1 GB RAM for $3.90 a month is enough for most bots, and a few of them side by side.
Free hosting tiers sleep, restart your bot at random or limit its hours. Your own server keeps it running, and you control the Python version, the database and the files.
01Which Server
| Bot | Plan | Price |
|---|---|---|
| One or a few simple bots | 1 vCPU, 1 GB RAM, 10 GB NVMe | $3.90/month |
| A bot with a database, or many bots | 1–2 vCPU, 2 GB RAM, 20 GB NVMe | $6.50/month |
| Heavy work: image or file processing, scraping | 2 vCPU, 6 GB RAM, 40 GB NVMe | $13/month |
Telegram's servers are in Amsterdam and Singapore, among others, so Amsterdam and Frankfurt are a good default; any of our six locations works for a normal bot.
Full root SSH access · NVMe storage · DDoS protection · No setup fee
02Put the Bot on the Server
The example is a Python bot on Ubuntu 24.04 or Debian 12. Log in over SSH as root:
- 1Create a user for the bot:
adduser --disabled-password --gecos "" bot - 2Install Python tools:
apt update && apt install -y python3-venv git - 3Copy the code as that user:
su - bot, thengit cloneyour repository or upload the files withscp. - 4Make a virtual environment:
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt - 5Store the token in
/home/bot/bot.envwith one line,BOT_TOKEN=123456:ABC..., thenchmod 600 bot.env. - 6Test it once by hand:
set -a; . ./bot.env; .venv/bin/python bot.py. Send it a message, then stop it with Ctrl+C.
Read the token in your code with os.environ["BOT_TOKEN"], so it never sits in the source or in Git.
03Run It as a Service
Create /etc/systemd/system/telegram-bot.service as root:
[Unit]
Description=Telegram bot
After=network-online.target
Wants=network-online.target
[Service]
User=bot
WorkingDirectory=/home/bot/mybot
EnvironmentFile=/home/bot/bot.env
ExecStart=/home/bot/mybot/.venv/bin/python bot.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targetThen start it and make it start at boot:
systemctl daemon-reload
systemctl enable --now telegram-bot
systemctl status telegram-botRestart=always brings it back five seconds after a crash. For a Node bot, change ExecStart to /usr/bin/node index.js; the rest stays the same.
04Logs and Updates
Read the log
journalctl -u telegram-bot -f shows everything the bot prints, live.
Deploy a new version
git pull as the bot user, then systemctl restart telegram-bot as root.
Several bots
one folder, one env file and one service file each (bot-shop.service, bot-alerts.service).
Back up the database
(SQLite file or a dump) off the server now and then.
05Long Polling or Webhooks?
Long polling means the bot asks Telegram for new messages itself. It works behind any firewall, needs nothing extra and is fine for almost every bot.
Webhooks mean Telegram sends each update to your server. They need a public HTTPS address: a domain pointing at the server, a certificate (Caddy or nginx with Let's Encrypt) and one of the ports Telegram allows, 443, 80, 88 or 8443. They're worth it for bots with very high traffic or when the bot already runs inside a web app. More on both on our Telegram bots page.
06Keep the Server Safe
- SSH only from your IP, using the firewall on your server page, and log in with a key.
- Turn on automatic security updates:
apt install -y unattended-upgrades. - Revoke a leaked token in @BotFather with
/revokeand put the new one inbot.env.
From $3.90 a month for a server with 1 vCPU, 1 GB RAM and 10 GB NVMe, which runs most bots and several small ones side by side.
- host telegram bot
- telegram bot hosting
- run telegram bot 24/7
- telegram bot vps
- deploy python telegram bot
- aiogram hosting