A Telegram bot to control your Linux server remotely.
Download the latest version from the Releases page.
We provide packages for:
- Debian/Ubuntu (
.deb) - RHEL/CentOS/Fedora/openSUSE (
.rpm) - Arch Linux (
.pkg.tar.zst) - Alpine Linux (
.apk)
The packages include a systemd service file. After installation, you can:
systemctl enable --now control_my_server_bot/startor/help: Show help and commands./ping: Return "Pong!"./status: Check server uptime, CPU, RAM, and disk space./get_cpu_usage: Show current CPU usage./get_ram_usage: Show current RAM usage./get_disk_usage: Show free disk space on all drives./get_services: List available services (all running or from a whitelist)./restart_server: Reboot the server.- Multi-user Support: Add and manage additional users.
/add_user <id>: Grant full permissions to a user (Owner only)./delete_user <id>: Remove a user (Owner only)./get_users: List all additional authorized users (Owner only).
- Logging to a dedicated Telegram channel.
- Whitelist for controllable services.
- High Availability: Configured to run with elevated privileges and scheduling priority to remain responsive even when the server is under extreme load.
- Linux server with
systemd(for running). - A Telegram bot token (from @BotFather).
- Your Telegram user ID (owner).
- A Telegram channel ID for logs (create one if needed).
- Go 1.26 or higher – optional: if you want to build from source.
The bot is configured via environment variables. You need to provide these in a .env file in the working directory.
| Variable | Description | Default |
|---|---|---|
TELEGRAM_BOT_TOKEN |
Required. Your Telegram bot token. | |
TELEGRAM_OWNER_ID |
Required. Your Telegram User ID. | |
TELEGRAM_LOG_CHANNEL_ID |
Required. Telegram Channel ID for logs. | |
CONTROLLED_SERVICES |
Comma-separated list of services the bot can control. | (All available) |
- Create a dedicated system user:
sudo useradd --system --shell /bin/false --home-dir /opt/control_my_server_bot control_my_server_bot_user
- Clone the repository and build the bot:
git clone https://github.com/edwinludik/control_my_server_bot.git cd control_my_server_bot go build -o control_my_server_bot ./src - Set up the installation directory:
sudo mkdir -p /opt/control_my_server_bot sudo cp control_my_server_bot /opt/control_my_server_bot/ sudo cp apply_update.sh /opt/control_my_server_bot/ sudo cp .env.example /opt/control_my_server_bot/.env # Edit /opt/control_my_server_bot/.env with your credentials sudo nano /opt/control_my_server_bot/.env - Assign permissions:
sudo chown -R control_my_server_bot_user:control_my_server_bot_user /opt/control_my_server_bot sudo chmod 700 /opt/control_my_server_bot sudo chmod 600 /opt/control_my_server_bot/.env
- Install as a systemd service:
- Copy the provided
control_my_server_bot.serviceto/etc/systemd/system/:sudo cp control_my_server_bot.service /etc/systemd/system/
- Update the
User,Group,WorkingDirectoryandExecStartin/etc/systemd/system/control_my_server_bot.serviceif they differ. For example, ensure it matches:User=control_my_server_bot_user Group=control_my_server_bot_user WorkingDirectory=/opt/control_my_server_bot ExecStart=/opt/control_my_server_bot/control_my_server_bot
- Reload systemd, enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable control_my_server_bot.service sudo systemctl start control_my_server_bot.service
- Copy the provided
- Configure Polkit/Sudoers: Follow the Security and Responsiveness Note section below to allow the bot to manage services.
For a cleaner installation, you can build and install a package for your specific distribution.
Building the packages:
- Install
nfpm(e.g., viago install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest). - Run the build for all platforms:
Or for a specific platform:
make packages
make package-deb # Debian/Ubuntu make package-rpm # RedHat/CentOS/Fedora/openSUSE make package-arch # Arch Linux make package-apk # Alpine Linux
Installing the package:
- Copy the generated package file to your server.
- Install it:
- Debian/Ubuntu:
sudo dpkg -i control_my_server_bot_*.deb - RedHat/CentOS/Fedora/openSUSE:
sudo rpm -i control_my_server_bot-*.rpm - Arch Linux:
sudo pacman -U control_my_server_bot-*.pkg.tar.zst - Alpine Linux:
sudo apk add --allow-untrusted control_my_server_bot-*.apk
- Debian/Ubuntu:
Currently, we do not provide Flatpak or Snap packages.
- Flatpak is primarily designed for desktop applications with a GUI, while this bot is a system service.
- Snap support is not currently implemented in
nfpm(the tool we use for packaging).
We recommend using the native .deb, .rpm, .apk, or Arch packages for the best integration with your system.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/amazing-feature). - Commit your changes (
git commit -m 'Add some amazing feature'). - Push to the branch (
git push origin feature/amazing-feature). - Open a Pull Request.
Each Pull Request and push to main triggers a GitHub Action that:
- Builds the Go binary.
- Runs a security scan (
govulncheck). - Generates Linux packages (.deb, .rpm, .pkg.tar.zst, .apk) as artifacts.
This project is licensed under the MIT License - see the LICENSE file for details.
The bot runs as a dedicated non-root user (control_my_server_bot_user) for enhanced security. It uses Polkit (or a sudoers rule fallback) to allow restarting services and rebooting the server without requiring a password or root privileges for the bot process itself.
- Dedicated User: The bot runs as
control_my_server_bot_userwith restricted access. - Polkit/Sudoers Control: Only specific actions (
systemctl restart,reboot) are permitted for thecontrol_my_server_bot_useruser. - File Permissions: The bot automatically attempts to set restricted permissions (
0600) on the.envand SQLite database files, and the installation directory is restricted to thecontrol_my_server_bot_useruser. - Error Sanitization: System-level error details are logged to the private log channel but not sent directly to the user who triggered the command.
If you are installing manually and don't want to run the bot as root, you should:
- Create a dedicated user (e.g.,
control_my_server_bot_user). - Give the user ownership of the bot's directory.
- Configure Polkit by adding a rule in
/etc/polkit-1/rules.d/10-control_my_server_bot_user.rules:Note: This allows the user to restart ANY service. You may want to further restrict this if necessary.polkit.addRule(function(action, subject) { if (subject.user == "control_my_server_bot_user") { if (action.id == "org.freedesktop.systemd1.manage-units" || action.id == "org.freedesktop.login1.reboot" || action.id == "org.freedesktop.login1.reboot-multiple-sessions") { return polkit.Result.YES; } } });
Alternatively, use sudoers fallback (not recommended if Polkit is available):
Add the following to /etc/sudoers.d/control-bot:
control_my_server_bot_user ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart *, /usr/sbin/reboot
(Ensure the bot code calls reboot or systemctl directly, and the user has permissions).
The bot is also configured with high scheduling and I/O priority (Nice=-10, CPUSchedulingPolicy=rr, IOSchedulingClass=realtime) and protected from OOM-killing (OOMScoreAdjust=-1000). This ensures it remains responsive even when the server is under extreme load.