Skip to main content

Python app to launch sshd server from Telegram

Project description

SSH Telegram Manager

SSH Telegram Manager is a Telegram bot designed to launch your SSH daemon on demand. This tool allows you to keep your SSH port closed by default, enhancing security by only exposing it when you explicitly request it via Telegram.

Features

  • On-demand SSH: Start your SSH server only when needed via a Telegram command.
  • Automatic Shutdown: SSH server automatically closes after a configurable timeout.
  • External IP Display: Easily retrieve your server's external IP address via Telegram.
  • Secure by Default: Avoid permanent exposure of your SSH port to the internet.

Installation

  1. Install the package:

    pip install ssh_telegram_manager
    
  2. Obtain a Telegram Bot Token: Follow a guide like this one ( https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token ) to get your bot token: How to get Telegram Bot API Token

  3. Configure the bot:

    • Create the configuration directory if it doesn't exist:
      sudo mkdir -p /etc/ssh_telegram_manager/
      
    • Copy the default configuration file to the system-wide configuration path:
      sudo cp /path/to/your/cloned/repo/etc/ssh_telegram_manager/ssh_telegram_manager.default /etc/ssh_telegram_manager/ssh_telegram_manager
      
      (Replace /path/to/your/cloned/repo/ with the actual path where you cloned the ssh_telegram_manager repository).
    • Edit the copied configuration file (/etc/ssh_telegram_manager/ssh_telegram_manager) and replace YOUR_TELEGRAM_BOT_TOKEN with the token you obtained in step 2.
  4. Run the bot:

    ssh_telegram_manager
    

    For production environments, it's recommended to run this as a systemd service. A sample ssh_telegram_manager.service file is available in the etc/ directory of the repository.

  5. Enhance Security (Recommended): Once the ssh_telegram_manager is working correctly, disable your SSH daemon from starting automatically at boot. This ensures your SSH port is not permanently exposed to the internet.

    sudo systemctl disable ssh
    

Configuration

The main configuration file is located at /etc/ssh_telegram_manager/ssh_telegram_manager. It uses INI format and contains the following sections:

[Telegram]
Token = YOUR_TELEGRAM_BOT_TOKEN

[SSHD]
command_start = systemctl start sshd
command_stop = systemctl stop sshd
timeout = 60
  • [Telegram]

    • Token: Your Telegram Bot API token. This is mandatory for the bot to connect to Telegram.
  • [SSHD]

    • command_start: The shell command executed to start your SSH daemon. Default is systemctl start sshd. Adjust if your system uses a different command (e.g., service ssh start).
    • command_stop: The shell command executed to stop your SSH daemon. Default is systemctl stop sshd. Adjust if your system uses a different command.
    • timeout: The number of seconds the SSH daemon will remain active after being started by the /ssh_start command. After this period, command_stop will be executed. Default is 60 seconds.

Usage

Interact with your bot on Telegram using the following commands:

  • /ssh_start: Starts the SSH daemon on the server. It will automatically shut down after the configured timeout period. The bot will send a confirmation message with the server's hostname and the command executed.
  • /ip: Displays the external IP address of the server where the bot is running. This is useful if your server's IP changes or if you need to quickly share it.

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

ssh_telegram_manager-1.1.0.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ssh_telegram_manager-1.1.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file ssh_telegram_manager-1.1.0.tar.gz.

File metadata

  • Download URL: ssh_telegram_manager-1.1.0.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.3 CPython/3.13.13 Linux/7.0.8-gentoo

File hashes

Hashes for ssh_telegram_manager-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7b217a4481bf9210a1bcf5fbfee52cac7d9e5612cf3b1057a2382db4b9e69257
MD5 6fbce493c990d3863113c84369b64234
BLAKE2b-256 9f091adc4c7520f3e3c7accaa59713d78f6c61d4441472259861a3273c243205

See more details on using hashes here.

File details

Details for the file ssh_telegram_manager-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ssh_telegram_manager-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e096b3899995c5ad5a1d2cc6cf289bfa31420901b70ff7f7ffcd10d66ab87cfc
MD5 ee5796b0f255dfc483bcfe0c91f6b297
BLAKE2b-256 76764769dd6e5082a34eb520e263daf35c468b36c742c6b6c91236d2664b98b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page