A powerful server information manager bot for your Linux server, built using Python and the Telegram Bot API. Monitor GPU usage, manage disk space, execute scripts, and run custom commands directly from Telegram.
- Features
- Requirements
- Setup
⚠️ Security Notice- Running the Bot
- Bot Features
- Project Structure
- Configuration
- Troubleshooting
- License
✅ GPU Monitoring - Track active GPU processes and VRAM usage
✅ Disk Analysis - Analyze disk usage across /home with color-coded alerts
✅ Script Manager - Execute custom scripts with arguments
✅ Command Runner - Run arbitrary shell commands as your user
✅ Auto-login - Activate internet connectivity with one click
✅ Beautiful Formatting - Clean, readable Markdown output in Telegram
✅ User Authentication - Telegram ID-based access control
- Python 3.11+
- Linux Server with GPU support (NVIDIA GPU for GPU features)
- uv Astral (Python package manager)
git clone https://github.com/yourusername/Telegram-Linux-Manager.git
cd Telegram-Linux-Manageruv sync- Open Telegram and search for @BotFather
- Send
/newbotand follow the instructions - Copy the bot token provided (it looks like
123456789:ABCdefGHIjklmnoPQRstuvWXYZ)
- Search for @userinfobot on Telegram
- Start the bot and it will show your user ID
- Note this number down
cp .env.sample .envEdit .env with your favorite editor:
nano .envSet the following variables:
TOKEN=your_telegram_bot_token_here
USER_MAPPING={"your_telegram_user_id": "your_linux_username"}
SCRIPTS_DIR=~/script/scripts
Example:
TOKEN=123456789:ABCdefGHIjklmnoPQRstuvWXYZ
USER_MAPPING = "123456789:username,987654321:anotheruser"
SCRIPTS_DIR=~/scripts
For some features (like analyzing /home or GPU info), you may need sudo access without password:
sudo visudoAdd these lines at the end:
your_username ALL=(ALL) NOPASSWD: /usr/bin/nvidia-smi
your_username ALL=(ALL) NOPASSWD: /usr/bin/du
your_username ALL=(ALL) NOPASSWD: /path/to/script.shReplace your_username and paths accordingly.
if you are a sudouser in your server just add:
your_username ALL=(ALL) NOPASSWD: ALLCRITICAL: Never share or commit your .env file!
- ✅
.envis already in.gitignore - ✅ Keep your
TOKENsecret - ✅ Don't share your Telegram User ID publicly
- ✅ Review all scripts before execution
- ✅ Use in private chats only, never in groups
- ✅ Regenerate bot token if exposed
See SECURITY.md for detailed security guidelines.
cd /path/to/Telegram-Linux-Manager
uv run bot/main.pynohup python /path/to/bot/main.py > bot.log 2>&1 &Create /etc/systemd/system/telegram-bot.service:
[Unit]
Description=Telegram Linux Manager Bot
After=network.target
[Service]
# L'utente che deve eseguire lo script (NON usare root se possibile)
User=username
Group=group
# La cartella dove risiede il tuo codice (importante per file .env o database locali)
WorkingDirectory=/path/to/Telegram-Linux-Manager
# SE USI UN VIRTUALENV: metti il percorso completo dell'eseguibile python nel venv
# Esempio: /home/utente/bot/venv/bin/python main.py
ExecStart=/path/to/venv/bin/python /path/to/bot/main.py
# Riavvia il bot automaticamente se crasha
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetThen enable and start:
sudo systemctl enable telegram-bot
sudo systemctl start telegram-bot
sudo systemctl status telegram-botView logs:
sudo journalctl -u telegram-bot -f- Solo i tuoi processi - Shows only your active GPU processes
- Tutti i processi - Shows all GPU processes on the system
- Displays: GPU ID, PID, User, Memory Usage, Command
- Analizza /home - Scan entire
/homedirectory - Analizza /home/username - Scan only your home directory
- Path personalizzato - Analyze any custom path
- Color-coded alerts:
- 🟢 < 100GB
- 🟡 100-350GB
- 🟠 350-600GB
- 🔴 > 600GB
- Lists all
.shand.pyfiles inSCRIPTS_DIR - Execute scripts with one click
- Pass arguments to scripts
- Execute any shell command
- Runs as your user (not root)
- Perfect for one-off commands
- Max timeout: 30 seconds
- Activates internet connectivity on the server
- Requires
private/login_auto.shscript (based on your server) - One-click activation
Telegram-Linux-Manager/
├── bot/
│ ├── __init__.py
│ ├── main.py # Entry point
│ ├── command.py # Command handlers
│ ├── config.py # Configuration loader
│ ├── format.py # Output formatting
│ ├── helpers.py # Helper functions
│ ├── keyboards.py # Telegram keyboard layouts
│ ├── utils.py # Utility functions
│ ├── .env # Environment variables (DO NOT COMMIT)
│ └── .env.sample # Environment template
├── README.md # This file
├── SECURITY.md # Security guidelines
├── LICENSE # MIT License
└── pyproject.toml # Project metadata
| Variable | Description | Example |
|---|---|---|
TOKEN |
Telegram Bot Token | 123456789:ABCdefGHIjklmnoPQRstuvWXYZ |
USER_MAPPING |
User ID to Linux username mapping | {"987654321": "emanuele"} |
SCRIPTS_DIR |
Directory containing scripts | ~/script/scripts |
Add multiple users to USER_MAPPING:
USER_MAPPING={"user_id_1": "username_1", "user_id_2": "username_2"}
Only users in this mapping can access the bot.
- Check if
TOKENis correct - Verify bot token with @BotFather
- Ensure your Telegram ID is in
USER_MAPPING
- Your Telegram ID is not in
USER_MAPPING - Add your ID to the configuration and restart
- GPU not properly configured on server
- NVIDIA drivers not installed
- User doesn't have permission to run
nvidia-smi
- Large directories take time to analyze
- Timeout may occur with very large filesystems
- Consider analyzing smaller paths first
- Sudoers not configured properly
- Check
/etc/sudoersconfiguration - Run:
sudo -n nvidia-smito test sudo access
- Script is not in
SCRIPTS_DIR - Script doesn't have execute permissions:
chmod +x script.sh - Python script issues: verify shebang line
#!/usr/bin/env python3
Feel free to submit issues and enhancement requests!
This project is licensed under the MIT License - see the LICENSE file for details.
Please review SECURITY.md before deploying this bot to production.
Enjoy managing your Linux server from Telegram! 🚀