MCP SSH服务器
针对模型上下文协议的安全SSH服务器实现, enables远程命令执行和文件操作,同时支持基于密码和密钥的身份验证。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"ssh": {
"args": [
"%APPDATA%/npm/node_modules/mcp-ssh/dist/server.js"
],
"command": "node",
"env": {
"SSH_LOG_LEVEL": "info",
"SSH_PORT": "8889"
}
}
}
}
该服务需要配置环境变量:SSH_LOG_LEVEL、SSH_PORT
服务介绍
MCP SSH 服务器
一个强大的 SSH 服务器实现,用于模型上下文协议 (MCP)。该服务器通过 SSH 协议启用安全的远程命令执行和文件操作,支持基于密码和密钥的身份验证。
特性
- ✨ 安全的 SSH 连接管理
- 🔑 基于密码和密钥的身份验证
- 💻 远程命令执行
- 📁 文件操作(上传/下载)
- 📊 文件传输进度跟踪
- 🔐 权限管理
- 📂 目录操作
- 🚀 批量文件传输
- 📝 详细日志记录
安装
- 安装软件包:
npm install mcp-ssh
- 添加到你的 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" # if your key is protected
} | 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"
文件操作
# Upload file
$uploadForm = @{
file = Get-Item -Path "localfile.txt"
remotePath = "/remote/path/file.txt"
}
Invoke-RestMethod -Uri "http://localhost:8889/upload/test" -Method Post -Form $uploadForm
# Download file
Invoke-RestMethod -Uri "http://localhost:8889/download/test?remotePath=/remote/path/file.txt" -Method Get -OutFile "downloaded.txt"
目录操作
# List directory
Invoke-RestMethod -Uri "http://localhost:8889/ls/test?path=/remote/path" -Method Get
# Get connection status
Invoke-RestMethod -Uri "http://localhost:8889/status/test" -Method Get
开发
- 克隆仓库:
git clone https://github.com/shaike1/mcp-server-ssh.git
cd mcp-server-ssh
- 安装依赖项:
npm install
- 构建:
npm run build
- 启动服务器:
npm start
环境变量
SSH_PORT: 服务器端口(默认:8889)SSH_LOG_LEVEL: 日志级别(默认:info)
贡献
- 叉分仓库
- 创建特性分支 (
git checkout -b feature/amazing-feature) - 提交更改 (
git commit -m 'Add some amazing feature') - 推送到分支 (
git push origin feature/amazing-feature) - 打开拉取请求
许可证
MIT