Running Hermes on a VPS With Telegram
An agent you can message from anywhere.
Running Hermes on a VPS with a Telegram bot is one of the more useful shapes for a long-lived assistant: you message it from your phone, it reasons on a machine that never sleeps, and you pay for a small VPS instead of keeping a laptop open. The hard parts are operational rather than conversational: a bot token sitting in shell history, a service that dies after a reboot and stays dead, a voice note that fails because a dependency is missing, or a provider bill that arrives before you notice the agent has been looping. This guide covers the full path: provision the host, install Hermes, store credentials properly, run the gateway under systemd, find the logs, handle voice and files, define what the agent is allowed to touch, and monitor provider spend. It ends with a test checklist to run before you trust the bot with anything that matters.
Quick answer: create a dedicated Unix user for Hermes, install it pinned to a release where possible, store the Telegram bot token in a root-owned environment file, smoke-test the gateway in the foreground, then promote it to a systemd service with restart limits and logs you know how to read.
Version note: Hermes moves quickly, and command names, config keys and gateway setup steps change between releases. The invocations below show the shape of the workflow and the operating decisions that matter. Confirm exact syntax against the docs at hermes-agent.nousresearch.com/docs before you copy anything verbatim.
What You Are Building: Hermes on a VPS With a Telegram Gateway
The architecture is simple enough to keep in your head. A Hermes process runs on the VPS. Its messaging gateway holds an outbound connection to Telegram and receives your messages. Each message becomes a turn for the agent, which can use tools — shell, files, search, memory, skills — and reply.
Two consequences follow. First, you never need to open an inbound port; the connection is outbound, which is good for your firewall posture. Second, the agent's blast radius on that box is exactly the blast radius of the Unix user the service runs as. Most of the hardening advice below is really about controlling that second point.
Prerequisites for a Hermes Telegram Bot on a VPS
- A VPS with 2 vCPU and 2–4 GB RAM as a sane starting point; more if you plan to run builds, browsers or multiple agents. Ubuntu LTS or a comparable systemd-based distribution.
- SSH key access and a non-root sudo user. Disable password authentication.
- A Telegram account and a bot created via BotFather, which gives you a bot token.
- An API key for at least one model provider, ideally with billing alerts enabled on the provider side.
- Outbound HTTPS access from the VPS. Some hosting providers firewall egress by default; verify Telegram and your provider endpoints are reachable.
ffmpegif you want voice notes transcribed or audio files handled, plus whatever transcription provider the Hermes docs list as supported.- A dedicated Unix user and directory for the agent. Decide this before install, not after.
Step 1 — Prepare the VPS Host for a Long-Running Agent
Create the service user first so that installation never happens as root or as your personal login:
sudo adduser --system --group --home /opt/hermes hermes
sudo mkdir -p /opt/hermes/data /etc/hermes
sudo chown -R hermes:hermes /opt/hermes
sudo ufw allow OpenSSH
sudo ufw enable
sudo apt update && sudo apt install -y ffmpeg curl git ca-certificates
Set the timezone deliberately. Clock skew breaks TLS handshakes and produces confusing provider errors, and it is the kind of thing you only notice at the worst moment. Enable unattended security upgrades, and note that a kernel update may require a reboot — plan for one and rehearse it, because your restart policy is about to become load-bearing.
Step 2 — Install Hermes as the Dedicated Service User
Follow the installation path in the current Hermes docs, running the commands as hermes rather than as your sudo user. Check whether the installer offers a pinned version or a release tag; if it does, pin it. An agent that auto-upgrades itself on restart will eventually restart into a changed config schema at 3am, and you will debug it from your phone.
sudo -iu hermes
# run the documented install command here, pinned to a release if available
hermes --version
Keep everything the agent writes — memories, skills, session transcripts, downloaded attachments — inside /opt/hermes. That single decision makes backups, disk monitoring and later migration dramatically easier.
Step 3 — Create the Telegram Bot and Store the Token Safely
In BotFather, create the bot, set a clear name and description, and copy the token exactly once. Understand what that string is: it is full control of the bot's identity. Anyone holding it can read incoming messages, send messages as the bot, and register a webhook. Treat it as a production credential, not a config value.
Store it in a root-owned environment file with mode 600. The variable names below are illustrative; use the names the current Hermes docs expect.
sudo install -m 600 -o root -g hermes /dev/null /etc/hermes/hermes.env
sudo tee /etc/hermes/hermes.env > /dev/null <<'EOF'
HERMES_TELEGRAM_BOT_TOKEN=replace-me
HERMES_PROVIDER_API_KEY=replace-me
EOF
sudo chmod 600 /etc/hermes/hermes.env
Wire that file into the service via systemd's EnvironmentFile (shown in Step 6) instead of exporting variables in a shell profile or passing them as command-line arguments, where they appear in ps output. Do not put the token in a git repository, a notebook, a shared document, or a chat with another agent — agents that summarise their environment will happily echo it. If it ever leaks, use BotFather's revoke flow to rotate the token, update the env file, and restart the service; rotation is cheap, so do it without agonising.
Step 4 — Configure a Model Provider With a Spend Ceiling
Create a dedicated provider API key for this deployment rather than reusing your personal one, and set a hard monthly budget or spend alert at the provider if the dashboard supports it. That provider-side cap is your real backstop; anything configured inside the agent is a convenience, not a guarantee. Then configure the model and defaults in Hermes' config as documented, and resist the temptation to start with the largest model available — you can raise the ceiling once you know what normal usage looks like.
Step 5 — Smoke Test the Telegram Gateway in the Foreground
Do not start with systemd. Run the gateway in the foreground as the service user so errors print directly to your terminal:
sudo -iu hermes
# start the documented Telegram gateway command
# send the bot a direct message from your phone
Send a short text message, then a longer one, then a voice note. Watch what appears in the terminal and on disk under /opt/hermes. When a reply arrives, confirm where the session transcript was written and what files were created. This ten-minute detour is the difference between a five-minute fix and an hour of reading journal logs for a missing key.
Step 6 — Run Hermes as a systemd Service
Now promote it. The ExecStart line below is illustrative; replace it with whatever the docs give as the long-running gateway command.
# /etc/systemd/system/hermes.service
[Unit]
Description=Hermes agent (Telegram gateway)
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=hermes
Group=hermes
WorkingDirectory=/opt/hermes
EnvironmentFile=/etc/hermes/hermes.env
ExecStart=/usr/local/bin/hermes gateway --telegram
Restart=always
RestartSec=5s
StartLimitIntervalSec=300
StartLimitBurst=10
TimeoutStopSec=30
UMask=0077
NoNewPrivileges=yes
PrivateTmp=yes
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now hermes
systemctl status hermes --no-pager
journalctl -u hermes -n 50 --no-pager
On the restart policy: Restart=always is right for a messaging bot, because you want it back after a crash, an OOM kill or a provider blip. But unqualified always will also silently thrash through a config error forever. Pair it with the start-limit settings above so a genuinely broken unit stops and stays stopped, then alert on systemctl is-failed hermes rather than assuming it is up. NoNewPrivileges and PrivateTmp cost nothing and remove some easy escalation paths.
Step 7 — Find Hermes Logs: systemd, Transcripts, and Provider Usage
Three places matter, and conflating them is a common source of wasted hours.
- Service and gateway logs — journald. Use
journalctl -u hermes -fto follow, and--since '30 min ago'to catch a window. By default journald may be volatile on some images, so confirm persistence or your logs vanish on reboot. - Agent and session transcripts — written under the Hermes data directory. These are what you read to understand why the agent did something; journald only tells you it did not crash.
- Provider-side usage — the provider dashboard, which is authoritative for tokens and cost.
Two habits matter: rotate what you keep so a chatty bot cannot fill the disk, and be careful that transcripts containing message bodies and tool output are not world-readable. If you paste logs into an issue, assume they contain user messages and scrub accordingly.
Step 8 — Handle Telegram Voice Notes and File Uploads
Voice is the feature that most often "works on my laptop" and fails on the VPS, usually because a system dependency is absent. Confirm ffmpeg is installed and executable by the hermes user, confirm a transcription provider is configured and funded, and test with a five-second note as well as a two-minute one; long recordings are where timeouts and size limits surface. Do the same for documents and images: send a small text file, then a large one.
Telegram's Bot API imposes documented size limits on what a bot can download and upload, so very large attachments will need to be sent some other way — check the current limits rather than assuming. Whatever does arrive lands on disk in your data directory, which means three operational tasks: a quota on that directory, a cleanup policy for old attachments, and consistent permissions so uploaded filenames are never trusted as paths. Treat incoming file names as untrusted input, and keep the uploads directory out of any path the agent treats as code.
Step 9 — Define Permission Scope Before You Invite Anyone
This is the step people skip, and it is the one with the longest consequences. Answer these questions in writing before the bot meets a second human.
- Who can talk to it? Restrict by Telegram user ID and chat ID allowlist where Hermes supports it. For group use, check BotFather's group privacy setting, decide whether the bot answers every message or only mentions, and remember that in a group every participant inherits your token's spending.
- What can it execute? Decide which tools run without confirmation and which require approval. Shell and file-write tools on a box holding production credentials deserve friction.
- What can it read? The service user's home should not contain unrelated keys. If the agent needs access to a repository, give it a scoped deploy key or a read-only mount rather than your personal SSH key.
- Where does it write? Constrain it to
/opt/hermes. If you need stronger isolation, put the agent in a container with explicit mounts instead of granting the host user broad access. - Who reviews the record? Transcripts are your audit trail. Decide retention and who can read them, because they will contain whatever people typed.
A practical pattern for teams: one bot per trust level. A personal bot that can run shell commands stays in a DM with you; a team bot that answers questions in a channel gets a narrower toolset and a different provider key with its own budget.
Step 10 — Monitor Provider Spend and Keep a Kill Switch
Conversational agents cost more than people expect because context accumulates: long sessions, memory retrieval, tool output and subagent fan-out all bill as input tokens. Set up three layers. First, provider budget alerts by email or webhook, which you actually read. Second, an internal habit of reviewing usage weekly against a rough baseline of messages per day. Third, configuration guardrails — a maximum turn count, a cheaper default model for routine work with escalation only when needed, and a short retention window on session history so every reply does not carry a month of context.
Keep a kill switch you have tested: sudo systemctl stop hermes, plus revoking the provider key in the dashboard. Knowing that both take ten seconds is what lets you sleep while a long-lived agent runs unattended.
Test Checklist Before You Rely on the Bot
- Reboot the VPS and confirm the bot answers without you logging in.
kill -9the process and confirm systemd restarts it within seconds.- Introduce a deliberate config error and confirm the start limit stops the loop instead of thrashing.
- Rotate the bot token, update the env file, restart, and confirm messages still arrive.
- Send a voice note, an image, a small file and an oversized file; record what happens in each case.
- Message from a Telegram account that is not on the allowlist and confirm the bot ignores it.
- Check
journalctl -p err -u hermesafter a day of use for errors you did not notice live. - Confirm disk usage in the data directory after a week of attachments, and that cleanup runs.
- Verify the provider dashboard matches your expectations for spend per day.
Troubleshooting Edge Cases for Hermes Telegram Bots
- Duplicate replies. Usually two instances running, or a leftover webhook competing with polling. Check for stray foreground sessions, then confirm the gateway's registration mode.
- Silence after a restart. Often a stale offset or a failed reconnect. Look at the first fifty journal lines after boot rather than the last five.
- Works in DM, fails in group. Almost always privacy mode, admin rights, or an allowlist that only contains your user ID.
- Provider rate limits. Expect
429s during bursts. Confirm the agent backs off rather than retrying hot, and cap concurrency. - Disk pressure. Attachments and verbose transcripts are the culprits. Cap both.
- Long tasks and timeouts. A tool call that takes minutes may look like a dead bot. Prefer a pattern where the agent acknowledges immediately and reports back.
- IPv6-only hosting. Some providers hand you an IPv6-only box; verify outbound reachability before blaming the token.
- Upgrades mid-flight. Pin versions, stage upgrades, and keep a copy of your env file and unit outside the install directory.
FAQ: Hermes on a VPS With Telegram
Do I need a public IP or an open port?
No. Long polling is outbound, so a plain VPS with outbound HTTPS works. A webhook setup is the opposite: it needs a reachable HTTPS endpoint and a certificate, which is more moving parts than most personal deployments need.
Where should the Telegram bot token live?
In a root-owned file with mode 600, loaded by systemd through EnvironmentFile. Not in shell history, not in a repository, and not in a message to another agent.
Why does the bot sometimes reply twice?
Two processes are polling the same token, or a webhook and polling are both active. Run one instance per token, and make the systemd unit the only way it starts.
How do I know it is healthy without messaging it?
systemctl is-active hermes plus a journal tail covers liveness; a synthetic message once a day covers the path that actually matters, since a process can be alive and unable to reach Telegram.
Can I run several Hermes agents on one VPS?
Yes. Give each its own Unix user, directory, env file and unit name, so a failure in one cannot read or overwrite another's data.
What is the most common reason voice notes fail?
A missing or inaccessible ffmpeg, or a transcription provider that is unconfigured or out of credit. Test both under the service user, not your own login.
Maintenance Rhythm and Next Action
Once it is stable, the ongoing work is small: a weekly glance at provider spend and journal errors, a monthly dependency and Hermes upgrade on a staged basis, and a quarterly token rotation. Write down the two commands that stop the bleeding — stop the service, revoke the provider key — somewhere you can find them from a phone.
Your next action is concrete: provision the service user, install Hermes pinned to a release, and get a single text message answered in the foreground. Everything else in this guide is easier once one message round-trips end to end.
If you end up running more than one of these — a personal bot on a laptop, a team bot on a VPS, a scratch agent in Docker — keeping track of what is installed where gets awkward fast. OPAYA (opaya.dev) is a desktop workspace for installing, connecting and managing AI agents across local machines, remote servers and Docker, and its agent managers area is a reasonable place to keep an inventory of running agents and jump into a host when something stalls. See opaya.dev/agent-managers for current capabilities before you plan around them.



