README
ΒΆ
SSH MCP Server
Production-ready SSH command execution server for AI agents
Connection Pooling β’ PTY Interactive Support β’ Auto-Retry & Reconnection β’ Security Guard
π Overview
SSH MCP Server is a production-ready Model Context Protocol (MCP) server that empowers AI agents with secure, high-performance SSH command execution capabilities on remote servers.
The Problem:
// Traditional SSH integration
- New connection for every command (slow)
- No interactive command support
- Large output crashes the buffer
- Dangerous commands can slip through
The Solution:
// SSH MCP Server
- Connection pooling with keepalive β‘
- PTY support for top, htop, vim π₯οΈ
- Smart output truncation π
- Built-in command blacklisting π‘οΈ
- Auto-retry on broken connections π
Result: Production-ready SSH execution that scales.
β‘ Key Features
Performance
- π Connection Pooling - Reuse SSH connections to reduce handshake overhead
- β‘ Keepalive Detection - Automatic connection health checks
- π¨ Idle Cleanup - Auto-close connections after 5 minutes of inactivity
- π¦ Lightweight - Single Go binary with minimal dependencies
Developer Experience
- π₯οΈ PTY Support - Interactive commands like
top,htop,vimwork seamlessly - π Auto-Retry - Transparent reconnection on broken pipe or EOF errors
- π Output Truncation - Prevents buffer overflow with smart truncation (last 2000 bytes)
- π‘οΈ Type Safe - Full Go with static typing
Security
- π Command Blacklisting - Block dangerous commands like
rm -rf /,mkfs,shutdown - π Dual Authentication - Password or private key (PEM format)
- β οΈ Separated Streams - Distinct stdout/stderr for precise debugging
π¦ Installation
One-Line Install
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/SKIPPINGpetticoatconvent/go-ssh-mcp/raw/main/tools/ssh-mcp-installer.sh | sh
Build from Source
git clone https://github.com/SKIPPINGpetticoatconvent/go-ssh-mcp.git
cd go-ssh-mcp
go build -o ssh-mcp main.go
Binary will be in the current directory:
./ssh-mcp
Go Install
go install github.com/SKIPPINGpetticoatconvent/go-ssh-mcp@latest
Binary will be installed to
$GOPATH/bin/go-ssh-mcp(typically~/go/bin/go-ssh-mcp)
π§ Configuration
Claude Desktop
Add to claude_desktop_config.json:
{
"mcpServers": {
"ssh": {
"command": "/home/your-user/go/bin/go-ssh-mcp"
}
}
}
π‘ Use
~/go/bin/go-ssh-mcpif installed viago install, or the local path if built from source
π Config file locations:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json- Windows:
%APPDATA%\Claude\claude_desktop_config.json- Linux:
~/.config/Claude/claude_desktop_config.json
VS Code
code --add-mcp '{"name":"ssh","command":"/home/your-user/go-ssh-mcp/ssh-mcp"}'
Cursor
- Open Settings β MCP β Add new MCP Server
- Select Command type
- Enter:
/home/your-user/go-ssh-mcp/ssh-mcp
Windsurf / Cline
Add to your MCP config:
{
"mcpServers": {
"ssh": {
"command": "/home/your-user/go-ssh-mcp/ssh-mcp"
}
}
}
π― Quick Start
Basic Command Execution
{
"host": "192.168.1.100",
"port": "22",
"user": "admin",
"password": "your-password",
"command": "uname -a"
}
Result:
Linux server 5.15.0-generic #1 SMP x86_64 GNU/Linux
Using Private Key Authentication
{
"host": "192.168.1.100",
"port": "22",
"user": "admin",
"privateKey": "-----BEGIN OPENSSH PRIVATE KEY-----\n...\n-----END OPENSSH PRIVATE KEY-----",
"command": "whoami"
}
Interactive Commands with PTY
{
"host": "192.168.1.100",
"port": "22",
"user": "admin",
"password": "your-password",
"command": "top -bn1",
"usePty": true
}
Execute in Specific Directory
{
"host": "192.168.1.100",
"port": "22",
"user": "admin",
"password": "your-password",
"command": "ls -la",
"workingDir": "/var/log"
}
Upload File to Remote Server
{
"host": "192.168.1.100",
"port": "22",
"user": "admin",
"password": "your-password",
"localPath": "/home/user/config.json",
"remotePath": "/etc/app/config.json",
"overwrite": true
}
Download File from Remote Server
{
"host": "192.168.1.100",
"port": "22",
"user": "admin",
"password": "your-password",
"remotePath": "/var/log/app.log",
"localPath": "/tmp/app.log"
}
Upload Base64 Content
{
"host": "192.168.1.100",
"port": "22",
"user": "admin",
"password": "your-password",
"content": "SGVsbG8gV29ybGQh",
"remotePath": "/tmp/hello.txt"
}
π API Reference
ssh_execute Tool
Execute commands on remote servers via SSH.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
host |
string | β | Remote host address (e.g., 192.168.1.100) |
port |
string | β | SSH port (default: 22) |
user |
string | β | Remote username |
password |
string | β | SSH password (optional if using private key) |
privateKey |
string | β | SSH private key content (PEM format) |
command |
string | β | Command to execute |
workingDir |
string | β | Working directory for the command |
usePty |
boolean | β | Enable PTY for interactive commands |
scp_upload Tool
Upload files to remote servers via SFTP protocol.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
host |
string | β | Remote host address |
port |
string | β | SSH port (default: 22) |
user |
string | β | Remote username |
password |
string | β | SSH password |
privateKey |
string | β | SSH private key (PEM format) |
localPath |
string | β | Local file path (one of localPath or content required) |
content |
string | β | Base64-encoded file content |
remotePath |
string | β | Remote destination path |
overwrite |
boolean | β | Overwrite existing file (default: false) |
scp_download Tool
Download files from remote servers via SFTP protocol.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
host |
string | β | Remote host address |
port |
string | β | SSH port (default: 22) |
user |
string | β | Remote username |
password |
string | β | SSH password |
privateKey |
string | β | SSH private key (PEM format) |
remotePath |
string | β | Remote file path |
localPath |
string | β | Local save path (optional, returns Base64 if not provided) |
maxSize |
number | β | Maximum download size in bytes (default: 10MB) |
β οΈ Note: Either
passwordorprivateKeymust be provided for all tools.
π‘οΈ Security Features
Command Blacklisting
The following dangerous commands are blocked by default:
| Blocked Pattern | Risk Level | Description |
|---|---|---|
rm -rf / |
π΄ Critical | Recursive deletion of root |
rm -rf * |
π΄ Critical | Recursive deletion of current directory |
mkfs |
π΄ Critical | Filesystem formatting |
shutdown |
π High | System shutdown |
reboot |
π High | System reboot |
init 0 / init 6 |
π High | Runlevel changes |
dd if= |
π High | Raw disk operations |
| `:(){ : | :& };:` | π΄ Critical |
Best Practices
- Use Private Keys - More secure than passwords
- Limit User Permissions - Create dedicated SSH users with minimal privileges
- Network Isolation - Run MCP server in a trusted network environment
- Host Key Verification - Configure proper host key checking in production
ποΈ Architecture
Tech Stack
| Component | Technology |
|---|---|
| Runtime | Go 1.22+ |
| MCP SDK | mcp-go |
| SSH Library | golang.org/x/crypto/ssh |
| Protocol | Model Context Protocol (MCP) |
| Transport | stdio |
Connection Pool Design
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β SSH MCP Server β
βββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ βββββββββββββββββββββββ β
β β MCP Handler βββββΆβ Connection Pool β β
β βββββββββββββββ βββββββββββββββββββββββ€ β
β β user@host:port β connβ β
β β user@host:port β connβ β
β βββββββββββββββββββββββ β
β β β
β ββββββββββΌβββββββββ β
β β Idle Cleanup β β
β β (every 1 min) β β
β β TTL: 5 minutes β β
β βββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
Design Principles
- π Security First - Command blacklisting, structured error handling
- β‘ Performance - Connection pooling, keepalive detection
- π‘οΈ Reliability - Auto-retry, graceful error recovery
- π― Simplicity - Single tool, clear API
π§ Troubleshooting
"Either password or privateKey must be provided"
Cause: Neither authentication method was specified.
Solution: Provide either password or privateKey in your request.
"Failed to parse private key"
Cause: Invalid private key format.
Solution:
- Ensure the key is in PEM format
- Include the full key content with headers (
-----BEGIN ... -----) - Check for extra whitespace or encoding issues
"SECURITY_ERROR: The command contains restricted pattern"
Cause: Command matches a blacklisted pattern.
Solution:
- Review and modify your command to avoid dangerous patterns
- If legitimate use, consider modifying the blacklist in
main.go
Connection Timeout
Cause: Network issues or firewall blocking.
Solution:
- Verify host and port are correct
- Check firewall rules
- Ensure SSH service is running on the remote host
πΊοΈ Roadmap
β Completed
- Connection pooling with keepalive
- PTY support for interactive commands
- Auto-retry on connection failure
- Output truncation for large files
- Command blacklisting
- Dual authentication (password/key)
- Working directory support
- SCP/SFTP file upload/download
π Planned
- Port forwarding (tunneling)
- Multi-hop SSH (jump hosts)
- Custom timeout configuration
- Host key verification
- Session multiplexing
- Execute scripts from files
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License
MIT Β© SSH MCP Server Contributors
π Credits
Built with:
- mcp-go - Go MCP SDK
- golang.org/x/crypto - Go cryptography libraries
- Model Context Protocol - The protocol specification
Connection Pooling β’ PTY Support β’ Auto-Retry β’ Security Guard
Documentation
ΒΆ
There is no documentation for this package.