ServerGuard
MODULE 02 / TELEGRAM BOT

Telegram Bot

Security notifications and protection management from Telegram.

  • Linux server
  • telegram

Telegram Bot — a ServerGuard module that sends you notifications about security events on your server in Telegram and lets you manage protection directly from the chat: block and unblock IPs, change settings, view statistics and server status.

The bot runs on your Linux server and accesses data from other ServerGuard modules. You do not need to open the desktop application for this.


1. What the bot can do

  • notifications about IP blocking and unblocking;
  • notifications about SSH logins, including logins from a new IP;
  • notifications about failed login attempts (optional);
  • notifications about SSH key changes (SSH Key Guard);
  • notifications about system service changes;
  • a daily report;
  • management of blocks and the whitelist (whitelist);
  • configuring the threshold and block duration;
  • server status and the latest SSH log lines;
  • an inline button menu and commands.

2. How it works

ServerGuard modules on the server
(brute-force protection, SSH Key Guard, service monitoring)
              |
              v
       record events
              |
              v
        Telegram Bot
              |
              v
   filters, groups, sends
              |
              v
      your Telegram chat
              |
              v
  you press a button → the bot performs an action on the server

The bot checks for new events every few seconds. Old events are not sent again when the bot starts.


3. Connecting

The bot is linked to your Telegram account using a one-time code.

  1. In ServerGuard, open Telegram bot and install/configure the bot (you will need a token issued by @BotFather).
  2. Select Generate verification code and copy the code.
  3. Open your bot in Telegram and send:
/start CODE
  1. The bot will delete the message with the code from the chat and confirm registration.

After that you will see the main menu.

Important: - the code is valid for 5 minutes; if it has expired, create a new one; - after several incorrect codes in a row, the bot temporarily stops accepting attempts; - the bot works only in a private chat.


4. Access: a single owner

The bot serves only one owner — the person who registered with the code.

  • Messages and buttons from other users are ignored or rejected.
  • If you generate a new code and another account activates it, access transfers to the new account. The previous owner will receive a notification about this.
  • Settings and the list of known IPs are preserved when the owner changes.

Do not share the bot token or verification codes with anyone.


5. Main menu

Open the menu with the /menu command.

Button What it shows
📊 Status Protection status and statistics for 24 hours and all time
🚫 Blocks Active blocks, unblock buttons
📜 Events Latest SSH events
🔑 Logins Latest successful logins
🏴‍☠️ Top attackers The most active IPs over 24 hours or 7 days
🖥 Server Load, memory, disk, uptime
🛡 Protection Protection settings
✅ Whitelist List of trusted IPs
🔔 Notifications Notification settings
🧾 SSH logs Latest SSH log lines

6. Which notifications you receive

Event When it arrives
🚫 IP blocked IP blocked automatically or manually
✅ IP unblocked The block expired or was lifted
🔑 SSH login Successful login (if enabled) or login from a new IP
⚠️ Failed SSH attempts Failed login attempts (disabled by default)
🔐 SSH key added / removed / changed authorized_keys changed
🔧 Service changed Service started, stopped, or changed
📅 Daily report Daily summary

Many notifications contain action buttons — for example, block an IP or add it to the whitelist with one tap.


7. Block notification

It shows:

  • the blocked IP and its geolocation (if enabled);
  • the number of failed attempts;
  • the block duration and end time;
  • the reason.

Buttons: 🔓 Unblock, ✅ Add to whitelist, 🔎 Info.


8. SSH login notification

It contains the user, IP, geolocation, authentication method and time.

If the login was made from an IP that has had no successful logins before, the bot marks it as 🆕 New IP. Such a notification arrives with increased priority. If it was not you, press 🚫 Block immediately.

Buttons: 🚫 Block, ✅ Add to whitelist, 🔎 Info.


9. SSH key changes

These notifications are generated by the SSH Key Guard module. The bot reports:

  • what exactly happened: the key was added, removed, or changed;
  • the account and the authorized_keys file;
  • the key type, fingerprint and comment;
  • who made the change: user, process, command (if auditd is available);
  • the source IP address, if it could be determined.

Removing a key is considered a critical event. If you did not make the change, check the server immediately.


10. Service notifications

The bot reports changes to system services: start, stop, state change.

  • Service and noisy processes (sessions, updates, timers, etc.) are filtered out.
  • Identical events for the same service are not repeated for 10 minutes.
  • Stopping important services — SSH, the firewall, fail2ban, auditd, ServerGuard — arrives as a critical notification.

11. Daily report

Once a day (by default at 9:00 server time) the bot sends a summary for the last 24 hours:

  • the number of failed attempts and unique attacking IPs;
  • the number of successful logins;
  • SSH key changes;
  • new and active blocks;
  • top attackers and the list of logins.

You can choose the sending hour: 6, 9, 18 or 22. The report can be disabled.


12. Configuring notifications

Open 🔔 Notifications and tap the items — ✅ enabled, ❌ disabled.

Item What it does
⭐ Important only Hides secondary events
🚫 Blocks Notifications about blocks
✅ Unblocks Notifications about unblocks
🔑 All successful logins Every successful login
🆕 Login from a new IP Login from an unknown IP
⚠️ Failed attempts Failed attempts
🔧 Service changes Service events
🔐 SSH key changes SSH key changes
🌍 IP geolocation Show country and provider
📅 Daily report Daily report

The Important only mode is enabled by default: unblocks, failed attempts and service starts are hidden so as not to distract you. Turn it off if you want to see everything.


13. Mute and critical notifications

To temporarily disable notifications:

/mute 60      — for 60 minutes (default 60, maximum 7 days)
/unmute       — turn back on

You can also press 🔕 1h, 🔕 8h or 🔔 Unmute in the notifications menu.

Critical notifications always arrive, even in mute mode: login from a new IP, SSH key removal, stopping an important service.


14. Flood protection

If there are a lot of events (for example, a mass attack is underway), the bot does not bury you in messages: some notifications are suppressed, and then a short 🌊 Flood protection message arrives with the number of skipped ones. The full data remains in the logs and in the Events and Status sections.


15. Managing protection

The 🛡 Protection section lets you change password-guessing protection parameters directly from Telegram:

Parameter Options
Enable / disable protection button
Failed attempt threshold 3, 5, 10, 20
Block duration 10 minutes, 1 hour, 6 hours, 24 hours, 7 days
Permanent block ON / OFF

Changes take effect within about 5 seconds. The selected item is marked with ●.

Loosen protection deliberately: too high a threshold or disabled protection makes password guessing easier.


16. Blocking and unblocking IPs

IP card. Send the bot any IP address — it will show a card:

  • geolocation and provider;
  • status (whether it is blocked, how much time is left);
  • whether it is in the whitelist;
  • the number of failed attempts and logins over 7 days;
  • which usernames were tried;
  • the Block / Unblock and Add to / Remove from whitelist buttons.

Commands:

/ip 1.2.3.4              — IP card
/block 1.2.3.4           — block with default parameters
/block 1.2.3.4 60        — for 60 minutes
/block 1.2.3.4 perm      — forever
/unblock 1.2.3.4         — unblock

The 🚫 Blocks section shows active blocks with their duration; the Unblock all button lifts all blocks after confirmation.

You cannot block: IPs from the whitelist and the server's own IP.


17. Whitelist

Whitelist — trusted IPs that are not blocked automatically.

/whitelist                 — show the list
/whitelist add 1.2.3.4     — add
/whitelist del 1.2.3.4     — remove

You can also add and remove with buttons in the cards and notifications. If the IP was already blocked, adding it to the whitelist removes the block.

Only add addresses that you truly trust.


18. All commands

Command Purpose
/start CODE Owner registration
/menu Main menu
/status Status and statistics
/blocks Active blocks
/events Latest events
/top Top attackers
/server Server status
/ip IP IP information
/block IP [minutes \| perm] Block an IP
/unblock IP Unblock an IP
/whitelist [add \| del IP] Whitelist management
/mute [minutes] Disable non-critical notifications
/unmute Enable notifications
/help Help

19. Geolocation and privacy

For public IPs, the bot can show the country, city and provider (as well as a “hosting / VPN / proxy” label). To do this, the IP address is sent to an external geolocation service. No request is made for local addresses.

  • Geolocation is approximate and does not determine a person's real location.
  • If you do not want to share IPs with third parties, turn off 🌍 IP geolocation in the notification settings.

Keep in mind that notifications pass through Telegram servers. Do not send data through the bot that should not leave the server.


20. What the bot does not do

  • it does not replace server protection — it informs and executes your commands;
  • it does not block IPs without the ServerGuard protection module or without your command;
  • it does not see events that other modules do not record;
  • it does not work in groups or channels, only in a private chat with the owner;
  • it does not guarantee delivery during network or Telegram problems.

21. If something is not working

Problem What to check
The bot does not respond Whether the bot service is running (the Telegram bot section in ServerGuard → Check status, Show logs)
“No active code” Generate a new code in ServerGuard
The code has expired or is incorrect The code is valid for 5 minutes; create a new one and send it exactly as shown in ServerGuard
“Too many wrong attempts” Wait the indicated time and try again
No notifications Whether mute mode /mute is enabled; whether the needed items in 🔔 Notifications are enabled; whether Important only is enabled
No notifications about keys Whether SSH Key Guard is running
Blocking is not being performed The bot must run as root; ufw must be available on the server
Error “This is the server's own IP” You cannot block the server's own IP
Another account gained access Anyone who had a valid code could register; create a new code and register again

22. Recommendations

  • keep login from a new IP, blocks and SSH key changes enabled;
  • leave Important only on until you get used to the flow of events;
  • enable the daily report at a convenient time;
  • add your permanent addresses to the whitelist so you do not block yourself;
  • do not publish the bot token or verification codes (including in screenshots);
  • enable two-factor authentication in Telegram — access to your account gives access to block management;
  • use the bot together with the other modules: Security, SSH Hardening, SSH Key Guard, FileGuard.

This documentation describes how the Telegram Bot works at the user level. Internal implementation details belong to the developers' technical documentation.

Get started

Choose your platform

Download ServerGuard for your desktop.

WindowsDownload for Windows LinuxUbuntu, Fedora, Arch & more

Checking Windows download…