返回 MCP 目录
public公开dns本地运行

mcp-server-ssh

MCP SSH Server是一个基于SSH协议的远程服务器管理工具,支持安全连接、文件操作和命令执行。

article

README

🚀 MCP SSH 服务器

MCP SSH 服务器是一款功能强大的 SSH 服务器实现,专为模型上下文协议 (MCP) 打造。它借助 SSH 协议,实现安全的远程命令执行与文件操作,支持密码和基于密钥的身份验证,为用户提供高效、安全的操作体验。

🚀 快速开始

MCP SSH 服务器为您提供了安全便捷的远程操作能力,您可以按照以下步骤进行安装和使用。

✨ 主要特性

  • ✨ 安全的 SSH 连接管理:保障连接的安全性和稳定性。
  • 🔑 密码和基于密钥的身份验证:提供多种身份验证方式,满足不同安全需求。
  • 💻 远程命令执行:可在远程服务器上执行各种命令。
  • 📁 文件操作(上传/下载):支持文件的上传和下载,方便数据传输。
  • 📊 传输进度跟踪:让您实时了解文件传输进度。
  • 🔐 权限管理:对用户操作进行权限控制,确保数据安全。
  • 📂 目录操作:支持目录的列出、创建和删除等操作。
  • 🚀 批量文件传输:提高文件传输效率。
  • 📝 详细日志记录:记录操作过程,方便问题排查。

📦 安装指南

安装包

npm install mcp-ssh

配置Claude桌面

将以下内容添加到您的 Claude 桌面配置 (claude_desktop_config.json) 中:

{
  "mcpServers": {
    "ssh": {
      "command": "node",
      "args": ["%APPDATA%/npm/node_modules/mcp-ssh/dist/server.js"],
      "env": {
        "SSH_PORT": "8889",
        "SSH_LOG_LEVEL": "info"
      }
    }
  }
}

💻 使用示例

基础用法

密码认证

$body = @{
    id = "test"
    host = "example.com"
    port = 22
    username = "user"
    password = "pass123"
} | ConvertTo-Json

Invoke-RestMethod -Uri "http://localhost:8889/connect" -Method Post -Body $body -ContentType "application/json"

密钥认证

$body = @{
    id = "test"
    host = "example.com"
    port = 22
    username = "user"
    privateKey = Get-Content ~/.ssh/id_rsa | Out-String
    passphrase = "optional-key-passphrase"  # 如果您的密钥受密码保护
} | ConvertTo-Json

Invoke-RestMethod -Uri "http://localhost:8889/connect" -Method Post -Body $body -ContentType "application/json"

高级用法

执行命令

$execBody = @{
    id = "test"
    command = "ls -la"
} | ConvertTo-Json

Invoke-RestMethod -Uri "http://localhost:8889/exec" -Method Post -Body $execBody -ContentType "application/json"

文件操作

# 上传文件
$uploadForm = @{
    file = Get-Item -Path "localfile.txt"
    remotePath = "/remote/path/file.txt"
}
Invoke-RestMethod -Uri "http://localhost:8889/upload/test" -Method Post -Form $uploadForm

# 下载文件
Invoke-RestMethod -Uri "http://localhost:8889/download/test?remotePath=/remote/path/file.txt" -Method Get -OutFile "downloaded.txt"

目录操作

# 列出目录
Invoke-RestMethod -Uri "http://localhost:8889/dir/list" -Method Get

# 创建目录
Invoke-RestMethod -Uri "http://localhost:8889/dir/create?path=/remote/path/newdir" -Method Post

# 删除目录
Invoke-RestMethod -Uri "http://localhost:8889/dir/delete?path=/remote/path/existdir" -Method Delete

📚 详细文档

开发步骤

克隆仓库

git clone [仓库地址]
cd mcp-ssh

安装依赖项

npm install

构建项目

npm run build

启动服务器

npm start

环境变量

| 属性 | 详情 | |------|------| | 模型类型 | 未提及 | | 训练数据 | 未提及 | | SSH_PORT | SSH 服务端口,默认值为 8889 | | SSH_LOG_LEVEL | 日志级别,可选值为 debug, info, warning, error,默认值为 info |

贡献指南

  1. Fork 本仓库
  2. 创建功能分支
  3. 提交更改
  4. 推送到您的分支
  5. 创建 Pull Request

📄 许可证

本项目采用 MIT 许可证。

help

运行方式说明

cloud

托管运行

托管运行通常表示这个 MCP Server 由服务方环境承载,用户一般按页面提供的连接方式或授权流程接入,不需要在本地长期启动一个 MCP 进程

  1. 打开服务方连接页
  2. 完成授权或复制端点
  3. 在 MCP 客户端中连接
terminal

本地运行 / 其它方式

本地运行通常需要用户在自己的电脑或服务器上安装依赖,把 server_config 复制到 MCP 客户端,并按 env_schema 补齐环境变量、密钥或其它配置

  1. 复制 server_config
  2. 安装所需依赖
  3. 补齐环境变量后重启客户端