mcp-ssh
This MCP server provides AI assistants with secure remote server management over SSH, including command execution, file transfer, host discovery, and audit capabilities. It offers the following key features:
Command execution: Run single or batch commands on remote hosts, with options for shell selection, timeouts, environment variables, and an explicit allow-dangerous flag.
Host discovery: List configured hosts from ~/.ssh/config and scan networks for SSH-enabled hosts with optional banner detection.
File transfer: Upload/download files and directories with atomic writes, SHA-256 checksums, and sensitive path protection.
Remote file management: List directories, get file stats, create directories, and delete files/directories with recursive options.
Security review modes: Dynamically switch between off, whitelist, manual, and smart modes to control command execution.
Audit logs: Query read-only action logs for monitoring.
Enhanced security: Strict host-key verification, dangerous command interception, credentials redaction, resource limits, and cross-platform support (Windows, Linux, WSL2).
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-ssh run 'ls -la' on myserver"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-ssh
跨平台 SSH MCP 服务器 — 让 AI 助手安全地管理远程服务器。
📦 当前文档为
main分支(完整版)
版本
分支
说明
main(当前)
main完整版:15 个 MCP 工具(含
ssh_scan网络扫描、独立文件工具),含质量与安全加固简化版
lite11 个 MCP 工具,文件类操作合并为
ssh_filesystem,移除ssh_scan极速版
fastGo 1.26 实现,8 个 MCP 工具,单二进制 ~10MB、启动 ~48ms、零环境依赖
版本:1.0.1(2026-08-10,质量与安全加固)
平台:Windows、Linux(含 WSL2)。macOS 不支持
语言:English | 简体中文
版本家族(一主二分支)
本项目维护三个并行版本,共用同一套 envelope 契约、4 模式审核与防御纵深,客户端可无感切换:
版本 | 分支 | 实现 | 工具数 | 定位 | 适用场景 |
完整版 |
| Python + Paramiko | 15 | 功能最全 | 需要网络扫描、批量命令、目录传输 |
简化版 |
| Python + Paramiko | 11 | 功能裁剪 | 文件操作合并、无需扫描 |
极速版 |
| Go 1.26 | 8 | 性能优先 | 单二进制、毫秒启动、零依赖 |
功能差异对比
能力 | main | lite | fast |
| ✅ | ✅ | ✅ |
| ✅ | ✅ | ✅ |
| ❌ 4 个独立工具 | ✅ 合并 | ✅ 合并 |
| ✅ | ❌ | ❌ |
| ✅ | ✅ | ❌ |
| ✅ | ✅ | ❌ |
| ✅ | ✅ | ✅ |
审核模式(off/whitelist/manual/smart) | ✅ | ✅ | ✅ |
防御纵深(注入/危险命令拦截) | ✅ | ✅ | ✅ |
严格 host key 策略 | ✅ | ✅ | ✅ |
envelope 契约兼容 | ✅ | ✅ | ✅ |
启动延迟(含握手) | ~1749ms | ~1749ms | ~48ms |
部署体积 | venv 58MB | venv 58MB | 单二进制 10.6MB |
环境依赖 | Python + uv/venv | Python + uv/venv | 零 |
选择建议:日常管理服务器选 main;追求简洁选 lite;对启动速度和部署体积敏感(如 CI、无 Python 环境)选 fast。
Related MCP server: mcp-ssh
快速开始(5 分钟)
1. 安装依赖
需要 Python 3.10+ 与 uv:
# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Linux / macOS
curl -LsSf https://astral.sh/uv/install.sh | sh2. 获取代码并安装
git clone https://github.com/albertm88/mcp-ssh.git
cd mcp-ssh
uv sync # 创建虚拟环境并安装依赖3. 配置 SSH 连接(~/.ssh/config)
Host myserver
HostName 192.168.1.100
User ubuntu
IdentityFile ~/.ssh/id_ed25519ssh myserver "echo ok" # 先手动验证 SSH 可连
ssh-keyscan -H myserver >> ~/.ssh/known_hosts # 信任主机密钥(首次必做)无密钥时可用密码:设置环境变量
SSH_PASS_MYSERVER(别名大写、点/横线转下划线)。 本工具默认拒绝未知主机密钥;未预置指纹的连接会失败返回HOST_KEY_MISMATCH。
4. 配置 MCP 客户端(通用格式)
所有 MCP 客户端(Claude Desktop、VS Code、Cursor、Trae、Qoder、Codex 等)使用同一套 JSON 配置,仅配置文件路径不同:
{
"mcpServers": {
"ssh": {
"command": "uv",
"args": ["run", "--directory", "/绝对路径/mcp-ssh", "python", "server.py"],
"env": { "SSH_REVIEW_MODE": "whitelist" }
}
}
}把上面这段 JSON 加入你客户端的 MCP 配置文件:
客户端 | 配置文件位置 |
Claude Desktop |
|
VS Code | 工作区 |
Cursor |
|
Claude Code / Codex CLI |
|
其他 | 在客户端 MCP 设置中添加同名 JSON 块 |
Windows 注意:路径用
/或\\,如D:/mcp-ssh。配置后重启客户端生效。
5. 验证安装
# 一键验证(环境、依赖、SSH 配置、MCP 握手、真实调用)
uv run python scripts/verify-install.py myserver期望输出(全部 PASS):
[1/5] 环境检查 Python / uv
[2/5] 依赖检查 mcp / paramiko / charset_normalizer
[3/5] SSH 配置检查 config 存在、主机别名、known_hosts
[4/5] MCP 协议验证 tools/list → 15 个工具
[5/5] 真实调用验证 ssh_exec(myserver, hostname) → 成功
结果: 12/12 PASS在 AI 客户端中测试:"请用 ssh_list_hosts 查看配置的主机,然后 ssh_exec 执行 hostname"
工具一览(15 个)
类别 | 工具 | 说明 |
命令执行 |
| 单条 / 批量执行命令 |
主机发现 |
| 列出配置主机 / 扫描网段 |
文件传输 |
| 单文件 / 目录传输(原子写 + SHA-256 校验) |
远端文件 |
| 目录列表 / 状态 / 创建 / 删除 |
审核管理 |
| 查看 / 切换审核模式 |
审计查询 |
| 查询最近行为日志(只读) |
所有工具返回统一 envelope(status / error.code / data / text),详见 结果契约。
安全机制
四模式审核(默认 whitelist)
模式 | 行为 | 适用场景 |
| 全部放行 | 开发调试 |
| 仅白名单命令 | 生产(默认) |
| 每条命令人工确认 | 关键服务器 |
| 智能判断,不确定转人工 | 日常运维 |
ssh_get_review_mode() # 查看当前模式
ssh_set_review_mode("smart") # 切换模式manual 模式自动选择确认通道:客户端弹框(支持 elicitation 的 IDE)→ 本地终端 → 无通道时拒绝执行(fail-closed)。
其他安全边界
严格 host-key:未知/错误指纹在认证前拒绝(
HOST_KEY_MISMATCH),不自动接受敏感路径保护:
/etc/passwd、~/.ssh/id_*等禁止读写;路径拒绝./..组件资源限制:文件大小 / 目录大小 / 深度 / 扫描地址 / 输出配额,
off模式也不可关闭凭据脱敏:密码、私钥、环境变量值不入日志;日志中
export K=V值替换为***危险命令拦截:
rm -rf /、mkfs、shutdown等需allow_dangerous=True
架构
┌─────────────────┐ stdio ┌─────────────┐
│ MCP Client │ ◄────────────► │ mcp-ssh │
│ (Claude/VSCode/ │ │ Server │
│ Trae/Qoder/ │ │ │
│ Codex/Cursor) │ │ │
└─────────────────┘ └──────┬──────┘
│
┌─────────────────────┼─────────────────────┐
│ │ │
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ SSH Tools│ │ Review │ │ Logger │
│ │ │ Engine │ │ │
│ ssh_exec │ │ │ │ JSON-lines│
│ ssh_scan │ │ 4 modes │ │ to disk │
│ ssh_upload│ │ │ │ (脱敏) │
│ ... │ │ whitelist│ └──────────┘
└────┬─────┘ │ manual │
│ │ smart │
│ │ off │
│ └────┬─────┘
│ │
▼ ▼
┌─────────────────────────────────┐
│ Paramiko SSH Client │
│ (key auth → password fallback) │
└─────────────────────────────────┘环境变量
变量 | 默认 | 说明 |
|
| 审核模式:off / whitelist / manual / smart |
| - | 全局 / 单主机密码 |
| 系统 known_hosts | 自定义可信主机密钥文件 |
|
| 白名单规则文件 |
|
| manual 确认通道:elicit / local / auto |
|
| 日志文件与级别 |
故障排除
问题 | 解决 |
| 运行 |
| 检查密钥或 |
| 先 |
命令被拒绝 | 切 |
MCP 客户端无响应 | 手动运行 |
项目结构
mcp-ssh/
├── server.py # MCP 服务器(15 个工具)
├── review.py # 四模式审核引擎
├── host_keys.py # 严格主机密钥校验
├── results.py # 统一结果 envelope
├── logger.py # 日志(脱敏)
├── scripts/
│ ├── verify-install.py # 安装验证脚本(跨平台)
│ └── verify-linux.sh # Linux 本地端回归脚本
└── tests/ # 单元 / 契约 / 边界测试许可证
Available Tools
15 toolsssh_downloadC
从远程主机下载文件到本地。
Inputs: host (required), local_path (required), remote_path (required), timeout, +1 more.
ssh_download_dirB
从远程主机下载目录到本地(递归下载所有文件)。
Inputs: host (required), local_dir (required), remote_dir (required), timeout, +1 more.
ssh_execC
在远程主机上执行一条 shell 命令并返回结果。
Inputs: host (required), command (required), shell, timeout, +2 more.
ssh_exec_batchC
批量执行多条命令,支持错误中断。
Inputs: host (required), commands (required), timeout, stop_on_error.
ssh_get_audit_logsA
查询最近的行为日志(只读,供 AI 分析)。
读取 ~/.ssh/mcp-ssh.log(或 SSH_LOG_FILE),按事件聚合为统一行为视图, 返回每条含 timestamp/host/username/tool/args/status/duration_ms。 支持按 host / tool / since_minutes 过滤;输出受 limit 与大小上限约束。
Inputs: host, tool, limit, since_minutes.
ssh_get_review_modeA
获取当前审核模式及状态信息。
Inputs: no named parameters.
ssh_list_dirC
列出远程主机指定目录下的文件和子目录。
Inputs: host (required), timeout, remote_path, show_hidden.
ssh_list_hostsA
列出 ~/.ssh/config 中配置的主机别名(排除 * 通配项),跨平台适配。
Inputs: no named parameters.
ssh_mkdirC
在远程主机创建目录。
Inputs: host (required), remote_path (required), parents, timeout.
ssh_removeC
删除远程主机上的文件或目录。
Inputs: host (required), remote_path (required), timeout, recursive.
ssh_scanB
扫描局域网网段,发现开放指定端口(默认 SSH 22)的在线主机。
Inputs: port, detail, network, timeout, +1 more.
ssh_set_review_modeC
动态切换审核模式。可选: off / whitelist / manual / smart。
Inputs: mode (required).
ssh_stat_fileB
获取远程文件或目录的详细信息。
Inputs: host (required), remote_path (required), timeout.
ssh_uploadC
上传本地文件到远程主机。
Inputs: host (required), local_path (required), remote_path (required), timeout, +1 more.
ssh_upload_dirC
上传本地目录到远程主机(递归上传所有文件)。
Inputs: host (required), local_dir (required), remote_dir (required), timeout, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 15 tools
Each tool targets a distinct operation—review mode, audit logs, execution, file transfer, directory management—with no meaningful overlap. ssh_exec and ssh_exec_batch are clearly differentiated as single vs. batch execution.
All tools follow the ssh_verb_noun pattern consistently, using snake_case throughout. The verb set is regular and predictable, making tool selection straightforward.
15 tools is well within the ideal range for an SSH server, covering execution, file transfer, directory ops, and host discovery without bloat.
The set provides comprehensive coverage for SSH workflows: command execution, file/directory transfer, remote filesystem manipulation, host listing/scanning, and audit/review controls. No critical gaps for common use cases.
Maintenance
Related MCP Connectors
SSH client, server management and one remote MCP URL for your machines, with human approvals.
Termalin's hosted MCP server. Claude, ChatGPT or any MCP client runs commands, moves files over SFTP, queries databases and reads server metrics and monitoring alerts on your servers, keylessly through Termalin Connectors: no SSH key is handed over and no inbound port is opened. Per-host command policy and an audit log. Needs a termal.in Pro or Team account (new accounts start with a 14-day Pro trial).
Secure and manage MCP servers through the Speakeasy AI Control Plane from your agent.
Linux server administration over OAuth MCP: shell, Docker, systemd, files and monitoring.
Related MCP Servers
- AlicenseAqualityCmaintenanceMCP server for SSH and local terminal access. Supports interactive commands, long-running processes, and TUI apps like tmux/zellij64MIT
- AlicenseNot gradedqualityDmaintenanceMCP server for SSH remote execution, file transfer, and file editing with automatic backup/trash and ~/.ssh/config integration.117 npm1MIT
- AlicenseAqualityDmaintenanceZero-config SSH/SFTP MCP server that lets an LLM client open temporary SSH/SFTP sessions to remote hosts, run commands, and upload/download files without holding any pre-baked credentials.177 npm2MIT
- AlicenseNot gradedqualityCmaintenance一组面向coding agent的MCP服务器,用于在SSH主机和WSL发行版中运行命令、管理任务,并以适合模型使用的方式读写远程文件。MIT