Skip to content

monokaijs/ok-ssh

Repository files navigation

SSH Server Manager Telegram Bot

A Telegram bot for managing SSH server connections using Telegram Topics. Each topic represents an interactive SSH terminal for a specific server.

Features

  • Topic-based SSH sessions: Each server connection gets its own topic
  • Multiple authentication methods: Password and SSH key authentication
  • SSH key management: Store and reuse SSH private keys
  • Interactive terminal: Execute commands directly in topics
  • File transfer: Upload and download files to/from servers
  • Session persistence: Working directory state survives bot restarts
  • Streaming output: Real-time command output updates

Prerequisites

  • Node.js (v14 or higher)
  • MongoDB
  • Telegram Bot Token (from @BotFather)
  • A Telegram Supergroup with Topics enabled

Installation

  1. Clone the repository
  2. Install dependencies:
npm install
  1. Create a .env file:
BOT_TOKEN=your_telegram_bot_token
MONGODB_URI=mongodb://localhost:27017/ssh-bot
  1. Start the bot:
npm start

Setup

  1. Create a Telegram Supergroup
  2. Enable Topics in group settings
  3. Add the bot to the group
  4. Grant the bot admin permissions to manage topics

Usage

Connecting to a Server

Interactive mode:

/connect

The bot will ask for:

  • IP address
  • Port number
  • Username
  • Authentication method (password or SSH key)

Quick mode:

/connect username@192.168.1.100:22
/connect 192.168.1.100:22

SSH Key Management

Add a new SSH key:

/addkey

Then either:

  • Upload the key file (e.g., id_rsa, mykey.pem) - filename becomes the key name
  • Send as text in this format:
MyKeyName
-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----

List stored keys:

/listkeys

Delete a key:

/deletekey

Terminal Commands

Once connected, send any command in the server's topic:

ls -la
cd /var/www
cat file.txt

The bot maintains your current working directory, so relative paths work correctly.

Check current directory:

/pwd

File Transfer

Download a file:

/download /path/to/file.txt

Upload a file: Simply send a file to the server's topic, and it will be uploaded to the current working directory.

Disconnecting

/disconnect

Security Notes

  • SSH keys are stored in MongoDB - ensure your database is properly secured
  • Password authentication messages are deleted immediately after use
  • Use environment variables for sensitive configuration
  • Consider encrypting SSH keys at rest in production

License

Private

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors