Telegram bot that runs Linux shell commands
Project description
pebbles_bot
Table of content
Introduction
Pebbles is a bot which allows users to run shell commands on their Linux servers from Telegram.
It is designed to be self-hosted. To get it up and running clone repository on the server,
ask BotFather to create a bot,
save its API hash to ./pebbles_api
, and just run it!
What It Can Do Now
At this stage Pebbles is not very sophisticated, it can:
- Run commands locally.
- Establish a SSH connection to another host and run commands there.
What It Will Do In The Future
- Support more built-in commands to do various tasks.
- Support public key authentication for SSH connections.
- Send information from the server to Telegram (upon completion of a script, for example).
Is it secure to run a public bot with direct access to a server?
The bot's channel itself is encrypted and secure by default.
To verify this, run /setprivacy
on @BotFather
, then check if privacy settings are enabled.
However, the bot can still be found by its handle and access to the server could be compromised.
That is why Pebbles has a built-in whitelisting mechanism to only allow certain users to run
commands on it.
Example of pebbles_whitelist
0123456789
3141592653
0112358132
...
There is no limit on how much user IDs can be allowed, but the list cannot be empty. User ID
can be obtained from a public bot @userinfobot
, by calling /start
command on it.
So yeah, I'd say it is pretty secure :)
Deployment
-
Ask BotFather to create a bot, then save it's API key
-
Create a configuration file and paste your API key and authorized user IDs to it
---
pebbles:
api_key: '....................'
whitelist:
- '0123456789'
- '3141592653'
- Install the bot with pip
python -m pip install pebbles_bot
Note Alternatively the bot can be ran in a container, see Prefix
- Run Pebbles
pebot
Command Guide
/start
-> start interacting with Pebbles./help
-> print all available commands./mode
-> choose Pebbles modelocal
: run commands on the server it's deployedremote
: run commands on the remote server. To use this option a connection must be first established by/login
.
/login
-> establish a SSH connection to a remote host. User will be prompted for:- IP address or hostname.
If port is not specified (8.8.8.8:22) then port 22 will be used. - username
- password
If~/.ssh/config
has connection information (key and/or user), connection will still be established if a wrond password is entered. - confirmation
selectYes
to establish a connection,No
to cancel.
- IP address or hostname.
/logout
-> to terminate the SSH connection/run
-> run a shell command, where it runs depends on/mode
. After command call user will be prompted to enter a command, stdout or stderr will be returned
Prefix
Running Pebbles in a Docker container
Note This is not the recommended installation method, more like a fun alternative :)
Create a $HOME/.pebbles/pebbles.yaml
configuration file first
(.pebbles
will be mounted to the container) and run:
docker run -d --name pebot \
--volume $HOME/.pebbles:/root/.pebbles \
labbratnet/pebbles:0.1.1
Alternatively, there is a Docker image for this bot in Docker/Dockerfile
which can be customized. To use it, navigrate to Docker
and run:
docker build -t pebbles .
docker run -d --name pebot \
--volume $HOME/.pebbles:/root/.pebbles \
pebbles
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pebbles_bot-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f20acea2df9794241174f6843a096da0ecd46d51f4b20930d7b93e9456a60274 |
|
MD5 | f572302420b88ed4d2508c6dc9b54340 |
|
BLAKE2b-256 | 0d98336b49648fca97b4bba3b44cdff451d657ffafdcd0623a06bda916783c54 |