ssh-mcp-server
classfang/ssh-mcp-serverUpdated 25 days ago01

Remote#SSH#MCP Protocol#Remote Command ExecutionLicense: ISC LicenseLanguage: TypeScript

ssh-mcp-server

基于 SSH 的 MCP (Model Context Protocol) 服务器,允许通过 MCP 协议远程执行 SSH 命令。

项目介绍

ssh-mcp-server 是一个桥接工具,可以让 AI 助手等支持 MCP 协议的应用通过标准化接口执行远程 SSH 命令。这使得 AI 助手能够安全地操作远程服务器,执行命令并获取结果,而无需直接暴露 SSH 凭据给 AI 模型。

工具列表

工具名称描述
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.*"
      ]
    }
  }
}

注意:如果同时指定了白名单和黑名单,系统会先检查命令是否在白名单中,然后再检查是否在黑名单中。命令必须同时通过两项检查才能被执行。

演示

Cursor 接入

demo_1.png

demo_2.png

Installation

Claude
Claude
Cursor
Cursor
Windsurf
Windsurf
Cline
Cline
Witsy
Witsy
Spin AI
Spin AI
Run locally with the following command:
Terminal
Add the following config to your client:
JSON
{
  "mcpServers": {
    "ssh-mpc-server": {
      "env": {},
      "args": [
        "-y",
        "@fangjunjie/ssh-mcp-server",
        "--host 192.168.1.1",
        "--port 22",
        "--username root",
        "--password pwd123456"
      ],
      "command": "npx"
    }
  }
}

MCPLink

Seamless access to top MCP servers powering the future of AI integration.

© 2025 MCPLink. All rights reserved.
discordgithubdiscord