A powerful Discord bot that lets you control Docker containers via SSH. Perfect for server admins who want to manage their infrastructure directly from Discord.
- Secure SSH Authentication - Support for both password and SSH key-based access to your VPS
- Docker Management via Slash Commands - Modern Discord slash commands for all operations
- Container Name-Based Control - Forget IDs, manage containers by name
- Beautiful Embedded Responses - Color-coded status indicators with Docker logo
- Command Autocomplete - Container name suggestions as you type
- Command Usage Logging - Track who's managing your infrastructure
- Comprehensive System Monitoring - For both Docker and VPS resources
- Interactive Terminal Session - Direct SSH access through Discord chat
| Command | Description | Example |
|---|---|---|
/docker-start <container> |
Start a stopped container | /docker-start nginx |
/docker-stop <container> |
Stop a running container | /docker-stop mongodb |
/docker-restart <container> |
Restart a container | /docker-restart redis |
/docker-logs <container> |
Show the last 50 lines of logs | /docker-logs postgres |
/docker-status <container> |
Show the current container status | /docker-status wordpress |
/docker-list |
List all containers with their status | /docker-list |
/docker-info |
Show Docker system information | /docker-info |
/ssh-system |
Show VPS system information (CPU/RAM/Disk) | /ssh-system |
/terminal |
Start an interactive terminal session | Type STOP to end session |
The /terminal command gives you direct SSH access through Discord:
- Start a session - Use
/terminalto begin an interactive session - Execute commands - Simply type any command in the channel
- Working directory tracking - The bot keeps track of your current directory
- Security restrictions - Dangerous commands (rm -rf /, etc.) are blocked
- Automatic timeout - Sessions end after 5 minutes of inactivity
- Session control - Type
STOPat any time to end the session - Focused interaction - Only the user who started the session can interact with it
- Node.js 16.x or higher
- A VPS with Docker installed
- SSH access to your VPS
- A Discord account with permission to create bots
-
Clone this repository
git clone https://github.com/nhyyebo/ssh-discord-bot.git cd ssh-discord-bot -
Install dependencies
npm install
-
Create a Discord bot
- Go to the Discord Developer Portal
- Click "New Application" and give it a name
- Go to the "Bot" tab and click "Add Bot"
- Under "Privileged Gateway Intents", enable:
- PRESENCE INTENT
- SERVER MEMBERS INTENT
- MESSAGE CONTENT INTENT
- Copy your bot token
-
Configure environment variables
- Create a
.envfile in the project root - Add the following variables:
# Required variables DISCORD_TOKEN=your_discord_bot_token_here SSH_HOST=your_vps_host SSH_PORT=22 SSH_USERNAME=your_ssh_username # Choose ONE authentication method: # Option 1: Password authentication SSH_PASSWORD=your_ssh_password # Option 2: SSH key file authentication (more secure) # SSH_PRIVATE_KEY_PATH=/path/to/your/private/key # Option 3: SSH key directly in environment variable # SSH_PRIVATE_KEY=-----BEGIN RSA PRIVATE KEY-----\nYOUR_PRIVATE_KEY_CONTENT_HERE\n-----END RSA PRIVATE KEY----- # Optional: Key passphrase (if your key has one) # SSH_KEY_PASSPHRASE=your_key_passphrase # Optional: User Restriction ALLOWED_USER_ID=your_discord_user_id_here- IMPORTANT: Never commit your
.envfile to Git or share your tokens publicly - If you accidentally expose your Discord token, immediately reset it in the Discord Developer Portal
- Create a
-
Run the bot
npm start
This bot can be run in a Docker container for easier deployment and management.
-
Clone this repository
git clone https://github.com/nhyyebo/ssh-discord-bot.git cd ssh-discord-bot -
Create a Discord bot and configure environment variables
- Follow steps 3-4 from the Standard Setup above
-
Build and run with Docker
# Build the Docker image docker build -t ssh-docker-bot . # Run the container docker run -d --name ssh-docker-bot --restart unless-stopped --env-file .env ssh-docker-bot
OR
-
Use Docker Compose (recommended)
# Start the bot docker-compose up -d # View logs docker-compose logs -f # Stop the bot docker-compose down
The included Dockerfile uses a multi-stage build process to create a lightweight container:
FROM node:18-alpine
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy app source
COPY . .
# Start the bot
CMD ["node", "index.js"]- Go to the "OAuth2" tab in the Discord Developer Portal
- Select "URL Generator"
- Select the following scopes:
botapplications.commands
- Select the following bot permissions:
Send MessagesEmbed LinksUse Slash CommandsAdd Reactions
- Copy and open the generated URL to invite the bot to your server
| Permission | Reason |
|---|---|
Send Messages |
Required to send command responses |
Embed Links |
Required to send embedded responses with Docker information |
Use Slash Commands |
Required to register and use slash commands |
Add Reactions |
For potential future interactive command features |
| Intent | Reason |
|---|---|
GUILDS |
Required to receive guild/server events |
GUILD_MESSAGES |
Required to receive message events |
MESSAGE_CONTENT |
Required to access message content for commands |
The SSH user specified in the configuration needs the following permissions on the VPS:
- Execute Docker commands (
dockergroup membership) - Read system information (for
/ssh-systemcommand)
- The bot supports both password and key-based SSH authentication
- Key-based authentication is strongly recommended over password authentication
- When using SSH keys, you can either:
- Point to a private key file on the system running the bot (
SSH_PRIVATE_KEY_PATH) - Provide the key content directly in the
.envfile (SSH_PRIVATE_KEY)
- Point to a private key file on the system running the bot (
- For maximum security, use a dedicated SSH user with restricted permissions
- Consider using an SSH key with a passphrase for an additional layer of security
- The bot never logs or exposes your SSH credentials to Discord users
- When using Docker, ensure your
.envfile is not included in the image build
- Automatic Container Name Completion - Type the first few letters and bot suggests container names
- Color-Coded Status Indicators
- π’ Green: Success/Running
- π΄ Red: Error/Stopped/Exited
- π‘ Yellow: Warning/Restarting/Paused
- π΅ Blue: Information/General state
- System Resource Monitoring - Real-time CPU, RAM, disk usage from your VPS
- Interactive Terminal - Execute any SSH command directly from Discord with the
/terminalcommand - Security-Focused Design - Dangerous terminal commands are automatically blocked
- Working Directory Tracking - Terminal sessions maintain current directory when using cd commands
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page at https://github.com/nhyyebo/ssh-discord-bot/issues.
If you need help setting up or using this bot, please open an issue on GitHub at https://github.com/nhyyebo/ssh-discord-bot/issues.

