SSH MCP 服务器
基于 SSH 的 MCP (Model Context Protocol) 服务器,允许通过 MCP 协议远程执行 SSH 命令。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"ssh-mpc-server": {
"args": [
"-y",
"@fangjunjie/ssh-mcp-server",
"--host 192.168.1.1",
"--port 22",
"--username root",
"--password pwd123456"
],
"command": "npx"
}
}
}
服务介绍
ssh-mcp-server
基于 SSH 的 MCP (Model Context Protocol) 服务器,允许通过 MCP 协议远程执行 SSH 命令。
项目介绍
ssh-mcp-server 是一个桥接工具,可以让 AI 助手等支持 MCP 协议的应用通过标准化接口执行远程 SSH 命令。这使得 AI 助手能够安全地操作远程服务器,执行命令并获取结果,而无需直接暴露 SSH 凭据给 AI 模型。
开源仓库
GitHub:https://github.com/classfang/ssh-mcp-server
工具列表
| 工具 | 名称 | 描述 |
|---|---|---|
| execute-command | 命令执行工具 | 在远程服务器上执行 SSH 命令并获取执行结果 |
| upload | 文件上传工具 | 将本地文件上传到远程服务器指定位置 |
| download | 文件下载工具 | 从远程服务器下载文件到本地指定位置 |
使用方法
MCP 配置示例
命令行选项
选项:
-h, --host SSH 服务器主机地址
-p, --port SSH 服务器端口
-u, --username SSH 用户名
-w, --password SSH 密码
-k, --privateKey SSH 私钥文件路径
-P, --passphrase 私钥密码(如果有的话)
-W, --whitelist 命令白名单,以逗号分隔的正则表达式
-B, --blacklist 命令黑名单,以逗号分隔的正则表达式
使用密码
{
"mcpServers": {
"ssh-mpc-server": {
"command": "npx",
"args": [
"-y",
"@fangjunjie/ssh-mcp-server",
"--host 192.168.1.1",
"--port 22",
"--username root",
"--password pwd123456"
]
}
}
}
使用私钥
{
"mcpServers": {
"ssh-mpc-server": {
"command": "npx",
"args": [
"-y",
"@fangjunjie/ssh-mcp-server",
"--host 192.168.1.1",
"--port 22",
"--username root",
"--privateKey ~/.ssh/id_rsa"
]
}
}
}
使用带密码私钥
{
"mcpServers": {
"ssh-mpc-server": {
"command": "npx",
"args": [
"-y",
"@fangjunjie/ssh-mcp-server",
"--host 192.168.1.1",
"--port 22",
"--username root",
"--privateKey ~/.ssh/id_rsa",
"--passphrase pwd123456"
]
}
}
}
使用命令白名单和黑名单
使用 --whitelist 和 --blacklist 参数可以限制可执行的命令范围,多个模式之间用逗号分隔。每个模式都是一个正则表达式,用于匹配命令。
示例:使用命令白名单
{
"mcpServers": {
"ssh-mpc-server": {
"command": "npx",
"args": [
"-y",
"@fangjunjie/ssh-mcp-server",
"--host 192.168.1.1",
"--port 22",
"--username root",
"--password pwd123456",
"--whitelist ^ls( .*)?,^cat .*,^df.*"
]
}
}
}
示例:使用命令黑名单
{
"mcpServers": {
"ssh-mpc-server": {
"command": "npx",
"args": [
"-y",
"@fangjunjie/ssh-mcp-server",
"--host 192.168.1.1",
"--port 22",
"--username root",
"--password pwd123456",
"--blacklist ^rm .*,^shutdown.*,^reboot.*"
]
}
}
}
注意:如果同时指定了白名单和黑名单,系统会先检查命令是否在白名单中,然后再检查是否在黑名单中。命令必须同时通过两项检查才能被执行。