sshmcp

ccjkcc/ssh-mcp-server
0 Stars 34 次浏览 更新于 2026-08-23

一个基于 Model Context Protocol (MCP) 的 SSH 连接服务器,允许 AI 助手通过 SSH 连接到远程服务器并执行命令、传输文件等操作。

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

SSH MCP Server

一个基于 Model Context Protocol (MCP) 的 SSH 连接服务器,允许 AI 助手通过 SSH 连接到远程服务器并执行命令、传输文件等操作。

功能特性

  • 🔌 SSH 连接管理 - 支持密码和密钥认证
  • 🖥️ 远程命令执行 - 在远程服务器上执行命令并获取输出
  • 📁 文件传输 - 支持上传和下载文件
  • 📂 远程文件列表 - 列出远程目录中的文件
  • 🔗 多连接管理 - 同时管理多个 SSH 连接

安装

npm install
npm run build

配置

在 Claude Desktop 或其他 MCP 客户端中配置:

{
  "mcpServers": {
    "ssh": {
      "command": "node",
      "args": ["/path/to/ssh-mcp-server/dist/index.js"]
    }
  }
}

配置文件

创建 ssh-config.json 文件来预配置 SSH 连接:

{
  "connections": {
    "server1": {
      "host": "192.168.1.100",
      "port": 22,
      "username": "admin",
      "password": "your-password"
    },
    "server2": {
      "host": "example.com",
      "port": 22,
      "username": "root",
      "privateKeyPath": "~/.ssh/id_rsa"
    },
    "server3": {
      "host": "10.0.0.50",
      "port": 2222,
      "username": "user",
      "privateKeyPath": "~/.ssh/id_ed25519",
      "passphrase": "key-passphrase"
    }
  }
}

配置字段说明:

  • host - IP 地址或主机名
  • port - SSH 端口(默认 22)
  • username - 用户名
  • password - 密码(可选,与密钥二选一)
  • privateKeyPath - 私钥文件路径(可选)
  • privateKey - 私钥内容字符串(可选)
  • passphrase - 私钥密码(可选)

可用工具

1. ssh_connect

手动连接到远程 SSH 服务器(不需要配置文件)。

参数:

  • host (必需) - 主机名或 IP 地址
  • username (必需) - 用户名
  • port (可选) - SSH 端口,默认 22
  • password (可选) - 密码
  • privateKey (可选) - 私钥内容
  • privateKeyPath (可选) - 私钥文件路径,如 ~/.ssh/id_rsa
  • passphrase (可选) - 私钥密码
  • timeout (可选) - 连接超时时间(毫秒),默认 20000

示例:

{
  "host": "example.com",
  "username": "root",
  "privateKeyPath": "~/.ssh/id_rsa"
}

2. ssh_connect_with_config

使用预配置文件连接(推荐)。

参数:

  • connectionName (必需) - 配置文件中的连接名称

示例:

{
  "connectionName": "server1"
}

3. ssh_list_configs

列出所有预配置的 SSH 连接。

4. ssh_disconnect

断开 SSH 连接。

参数:

  • connectionId (必需) - 连接 ID

5. ssh_list_connections

列出所有活动的 SSH 连接。

6. ssh_execute

在远程服务器上执行命令。

参数:

  • connectionId (必需) - 连接 ID
  • command (必需) - 要执行的命令
  • timeout (可选) - 命令超时时间(毫秒)

示例:

{
  "connectionId": "ssh-1234567890-1",
  "command": "ls -la /home"
}

7. ssh_upload_file

上传文件到远程服务器。

参数:

  • connectionId (必需) - 连接 ID
  • localPath (必需) - 本地文件路径
  • remotePath (必需) - 远程文件路径

8. ssh_download_file

从远程服务器下载文件。

参数:

  • connectionId (必需) - 连接 ID
  • remotePath (必需) - 远程文件路径
  • localPath (必需) - 本地文件路径

9. ssh_list_remote_files

列出远程目录中的文件。

参数:

  • connectionId (必需) - 连接 ID
  • remotePath (必需) - 远程目录路径

使用示例

方式1:使用配置文件连接(推荐)

  1. 先查看可用的配置:
使用工具 ssh_list_configs
  1. 使用配置名称连接:
使用工具 ssh_connect_with_config,参数:
{
  "connectionName": "server1"
}
  1. 执行命令:
使用工具 ssh_execute,参数:
{
  "connectionId": "ssh-1234567890-1",
  "command": "df -h"
}

方式2:手动连接

使用工具 ssh_connect,参数:
{
  "host": "192.168.1.100",
  "port": 22,
  "username": "admin",
  "password": "your-password"
}

上传文件

使用工具 ssh_upload_file,参数:
{
  "connectionId": "ssh-1234567890-1",
  "localPath": "/local/path/file.txt",
  "remotePath": "/remote/path/file.txt"
}

开发

# 开发模式(自动编译)
npm run dev

# 构建
npm run build

# 类型检查
npm run typecheck

安全提示

⚠️ 重要安全提醒:

  1. 不要在代码中硬编码密码
  2. 优先使用 SSH 密钥认证
  3. 妥善保管私钥文件,设置适当的文件权限(如 600)
  4. 使用 passphrase 保护私钥
  5. 生产环境中限制 SSH 访问权限

许可证

MIT

相关 MCP 服务