MCP SSH 服务器是一款功能强大的 SSH 服务器实现,专为模型上下文协议 (MCP) 打造。它借助 SSH 协议,实现安全的远程命令执行与文件操作,支持密码和基于密钥的身份验证,为用户提供高效、安全的操作体验。
MCP 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" # 如果您的密钥受密码保护
} | 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 |
本项目采用 MIT 许可证。