Skip to main content

Table of content

Introduction

Pebbles is a bot which allows users to run shell commands on their Linux servers from Telegram.
There are only 3 steps to get it up and running:

  1. Ask BotFather to create a bot and save its API key.
  2. Install the bot on the server where you wish to run commands using Python pip.
  3. Configure environment variables and run it!

More about the usage of Pebbles can be found on my blog post.

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.
  • Send a notification by piping stdout.
  • Users whitelist - only whitelisted users can run commands on the bot.

What It Will Do In The Future

  • More built-in commands to do various tasks without entering long commands.
  • Commands whitelist - only whitelisted commands can be run on the bot.
  • Log parser that will block users or even shut the bot down if it detects a malicious activity.

Is it secure to run a public bot with direct access to a server?

The bot's channel is encrypted via Telegram's proprietary protocol - MTProto, and the API also uses appropriate security measures, therefore there are no issues from Telegram's side. However, the bot is still a public service, and anyone on the internet can attempt to use it (if they find bot's handle). That is why Pebbles has a whitelisting mechanism to only allow certain users to run commands on it.
In general I'd say it's pretty safe to use, but don't use it on important production servers 😅

Deploy

  • Ask BotFather to create a bot, then save it's API key
  • Install the bot with pip python -m pip install pebbles_bot Note Alternatively the bot can be ran in a container, see Prefix
  • Define 2 environment variables:
    • PEBBLES_BOT_TOKEN - the API key of the bot
    • PEBBLES_BOT_USERS - a comma-separated list of Telegram user IDs that will be whitelisted. User ID can be obtained from a public bot @userinfobot, by calling /start command on it.
  • Optionally a yaml configuration file can be used to list users and set other options. See Configuration file for more details.

Run Pebbles

Pebbles provides two modes of operation: Proxy and Notification modes. In Proxy mode, will run commands that users send from Telegram on the server it's deployed on. And in Notification mode it will send a Linux command/service output to the user from the server.

Run in proxy mode:

pebot

Send notifications with Pebbles:

echo 'Testing Notifications!' | pebot --notify

Command Guide

  • /start -> start interacting with Pebbles.
  • /help -> print all available commands.
  • /mode -> choose Pebbles mode
    • local: run commands on the server it's deployed
    • remote: 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 using information from ~/.ssh/config. User will be prompted for:
    • hostname
      should be the same as in ~/.ssh/config
    • confirmation
      select Yes to establish a connection, No to cancel.
  • /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

Configuration file

The default location is $HOME/pebbles.yaml, but it can be changed by setting the PEBBLES_CONFIG environment variable.
Example of the configuration file:

whitelist_ids:
  - 123456789
  - 987654321

Note If both environment variables and configuration file are defined, the environment variables will take precedence.

Metadata

Release files for pebbles-bot 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pebbles-bot 0.3.3
File Size Uploaded Provenance
pebbles_bot-0.3.3.tar.gz 10.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pebbles-bot 0.3.3
File Interpreter ABI Platform
pebbles_bot-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / pebbles_bot-0.3.3.tar.gz

Download URL pebbles_bot-0.3.3.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
807faa9b2ce018adb26c9e2616ee08ba025b5f94c75c3355c6773f2009333a02
BLAKE2b-256 checksum
How to use checksums
3dc754ef388ebefec097d26f8dc6b61f93f2e0c5a26bcf28cf257fd05b7d19f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / pebbles_bot-0.3.3-py3-none-any.whl

Download URL pebbles_bot-0.3.3-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b38272908ac9ef9914d8be11f035960094e283e7b3b6f843258f6fe01bf370f
BLAKE2b-256 checksum
How to use checksums
3bbb6aae59cd4cc79715f9e638463c1e6ae8aca545a44f1ea0095552eee14b30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Security for pebbles-bot 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page