SSH MCP Server

SSH MCP Server

A secure remote server management tool based on MCP protocol, supporting SSH connections, command execution, and SFTP file transfers.

Category
访问服务器

README

SSH MCP Server

GitHub Stars License: MIT Node.js npm version npm downloads

A secure remote server management tool based on MCP protocol, supporting SSH connections, command execution, and SFTP file transfers.

The only MCP SSH tool that truly prevents AI from accidentally running commands on the wrong server.

If you find this project helpful, please give it a star on GitHub! Your support helps us improve!

English | 中文


Why SSH MCP Server?

Managing remote servers with AI assistants is powerful -- but also dangerous. When multiple servers are connected, AI models frequently mix up which server they're operating on. One wrong rm -rf on a production server, and you're in trouble.

SSH MCP Server is built from the ground up to solve this problem. Every safety mechanism is enforced server-side with cryptographic tokens -- the AI cannot bypass them, no matter what.

Safety guarantees other tools don't have:

  • Target Lock -- Tracks which server the AI is currently operating on. If it tries to switch targets, it must confirm first. No silent mistakes.
  • Alias-based routing -- Save servers with aliases like us-prod or jp-staging, then use exec(alias: "us-prod") instead of raw IPs. Harder to mix up.
  • Dangerous command detection -- 60+ patterns covering Docker, Kubernetes, databases, system commands. All require cryptographic token confirmation.
  • Multi-connection enforcement -- When multiple servers are connected, every operation MUST specify the target. No ambiguous defaults.
  • Environment labels -- Mark servers as production / staging / test. Every command output shows which environment it ran on.

Features

  • SSH Connection Management - Password/key authentication with connection pooling, private key supports both content and file path
  • Command Execution - Regular commands, sudo commands, batch execution, shell mode (bastion hosts)
  • SFTP Operations - Upload, download, list directories, create/delete files
  • Server Management - Save/list/remove server configurations with alias support
  • Credential Security - System Keychain encrypted storage (macOS/Windows/Linux)
  • Audit Logging - Records all operations with sensitive data masking
  • Persistent Shell Sessions - Multi-round interaction for bastion host scenarios
  • Target Lock Protection - Prevents AI from accidentally running commands on the wrong server

What's New

v0.8.1 (Latest)

  • Private Key File Path Support - privateKey parameter now accepts both key content and file paths
    • Previously you had to paste the entire key content; now you can just pass a path like /path/to/id_rsa.pem or ~/.ssh/id_rsa
    • Auto-detects format: -----BEGIN prefix = key content, otherwise treated as file path
    • Supports ~ home directory expansion

v0.7.0

  • Target Lock: Server Switch Protection - The core safety feature for multi-server scenarios
    • Tracks the AI's current operation target; switching servers requires explicit confirmation with a cryptographic token
    • Single server: zero overhead. Multi-server, same target: zero overhead. Only triggers on actual target switch.
    • Works across all tools: exec, exec_sudo, exec_shell, shell_send, and all SFTP operations
    • If both target switch and dangerous command confirmations are needed, they run in sequence (switch first)
  • Alias Support for All Tools - Use server aliases instead of raw host/port/username
    • exec(alias: "us-prod", command: "ls") -- routes to the saved server configuration
    • Available on all exec and SFTP tools via the new alias parameter
  • Server Environment Labels in All Outputs - Every command result now shows [Server: us-prod (root@1.2.3.4) | Env: PRODUCTION]
    • No longer limited to production only -- all environments are labeled
  • SFTP Multi-Connection Safety - SFTP operations now enforce the same multi-connection safety checks as command execution
    • SFTP results include server field with full identity information
  • Connect shows active connections - When connecting a second server, the response lists all active connections as a reminder

v0.6.0

  • Server Identity System - Commands return full server identity (host, port, username, environment, alias)
  • Confirmation Token Mechanism - Cryptographic tokens replace boolean flags; AI cannot forge confirmations
  • 60+ Dangerous Command Patterns - Docker, Kubernetes, databases, system services, Git, network, package managers
  • Multi-Connection Enforcement - Must specify target when multiple connections are active

v0.5.0

  • Persistent Shell Sessions - shell_send, shell_read, shell_close for multi-round bastion host interaction

View Full Changelog | All Releases


📦 Quick Start

Option 1: Run with npx (Recommended)

npx @erliban/ssh-mcp-server

Option 2: Global Installation

npm install -g @erliban/ssh-mcp-server
ssh-mcp-server

Option 3: Build from Source

git clone https://github.com/jiahuidegit/ssh-mcp-server.git
cd ssh-mcp-server
npm install
npm run build

🔄 Update to Latest Version

If using npx (Recommended)

npx automatically uses the latest version, just restart your MCP client:

# No manual update needed, npx always fetches latest
npx @erliban/ssh-mcp-server

If globally installed

# Update to latest version
npm update -g @erliban/ssh-mcp-server

# Or reinstall
npm install -g @erliban/ssh-mcp-server@latest

Check current version

npm list -g @erliban/ssh-mcp-server

🎮 MCP Client Configuration

This server supports all MCP-compatible clients. Here's an example with Claude Desktop:

Edit the configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "ssh": {
      "command": "npx",
      "args": ["-y", "@erliban/ssh-mcp-server"],
      "env": {
        "SSH_MCP_LOG_LEVEL": "info"
      }
    }
  }
}

For other MCP clients, please refer to their respective documentation for configuration methods.


⚙️ Environment Variables

Variable Description Default
SSH_MCP_LOG_LEVEL Log level (debug/info/warn/error) info
SSH_MCP_LOG_FILE Log file path stderr
SSH_MCP_CONN_TIMEOUT Connection timeout (ms) 30000
SSH_MCP_CMD_TIMEOUT Command timeout (ms) 60000
SSH_MCP_IDLE_TIMEOUT Idle connection timeout (ms) 300000
SSH_MCP_MAX_CONNECTIONS Maximum connections 10
SSH_MCP_DATA_DIR Data directory ~/.ssh-mcp
SSH_MCP_MASTER_PASSWORD Master password for file storage -

🛠️ MCP Tools

Connection Management

Tool Description
connect Establish SSH connection (password/key auth)
disconnect Disconnect specific or all connections

Server Management

Tool Description
save_server Save server configuration locally
list_servers List saved servers (supports group filtering)
remove_server Remove server configuration

Command Execution

Tool Description
exec Execute remote command (supports alias routing)
exec_sudo Execute with sudo privileges
exec_batch Batch execute on multiple servers
exec_shell Execute via interactive shell (for bastion hosts)
shell_send Send input to persistent shell session
shell_read Read shell session output buffer
shell_close Close persistent shell session

SFTP Operations

Tool Description
sftp_ls List directory contents (supports alias routing)
sftp_upload Upload file
sftp_download Download file
sftp_mkdir Create directory
sftp_rm Delete file or directory

System Tools

Tool Description
health_check Check connection status
get_logs Get audit logs
list_active_connections List all active connections with environment labels

💡 Usage Examples

Connect and Execute Command

User: Connect to 192.168.1.100 with username root and password 123456

Claude: [calls connect tool]
Connected to root@192.168.1.100:22

User: Check system load

Claude: [calls exec tool]
10:30:01 up 45 days, 2:15, 1 user, load average: 0.15, 0.10, 0.05

Upload Deployment File

User: Upload local /tmp/app.jar to server's /opt/app/

Claude: [calls sftp_upload tool]
Uploaded /tmp/app.jar -> /opt/app/app.jar

Batch Check Server Status

User: Check disk usage on all production servers

Claude: [calls list_servers, then exec_batch]
Server 10.0.0.1: 45% used
Server 10.0.0.2: 62% used
Server 10.0.0.3: 78% used ⚠️

Security Notes

  1. Target Lock - Tracks the AI's operation target; switching servers requires cryptographic token confirmation. Prevents the #1 cause of AI server misoperations.
  2. Credential Storage - Prefers system Keychain (macOS Keychain, Windows Credential Manager). Falls back to AES-256-GCM encrypted file storage when no desktop environment is available.
  3. Log Masking - Passwords, private keys, and other sensitive information are automatically masked.
  4. Dangerous Commands - 60+ patterns detected. All require token confirmation. Production environments get extra warnings.
  5. Connection Pool - Automatically cleans up idle connections to prevent resource leaks.
  6. Multi-Connection Safety - When multiple servers are connected, every operation must explicitly specify the target server.

📊 Star History

<a href="https://star-history.com/#jiahuidegit/ssh-mcp-server&Date"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=jiahuidegit/ssh-mcp-server&type=Date&theme=dark" /> <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=jiahuidegit/ssh-mcp-server&type=Date" /> <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=jiahuidegit/ssh-mcp-server&type=Date" /> </picture> </a>


🤝 Contributing

Issues and Pull Requests are welcome!


📄 License

This project is licensed under the MIT License.


⭐ If you find this project helpful, please give it a star!

🤝 Feel free to open issues for questions or submit PRs for improvements!

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选