A Telegram bot for managing SSH server connections using Telegram Topics. Each topic represents an interactive SSH terminal for a specific server.
- 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
- Node.js (v14 or higher)
- MongoDB
- Telegram Bot Token (from @BotFather)
- A Telegram Supergroup with Topics enabled
- Clone the repository
- Install dependencies:
npm install- Create a
.envfile:
BOT_TOKEN=your_telegram_bot_token
MONGODB_URI=mongodb://localhost:27017/ssh-bot- Start the bot:
npm start- Create a Telegram Supergroup
- Enable Topics in group settings
- Add the bot to the group
- Grant the bot admin permissions to manage topics
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
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
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
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.
/disconnect
- 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
Private