使用说明
mcp-ssh服务器
MCP SSH Command Server - 配置文件支持版v2.0.0
通过配置文件管理LLM隐藏机密信息,确保安全SSH实现连接Anthropic公司的Model Context Protocol (MCP)支持SSH命令执行服务器。 sudo增强版,包括问题修复和会话恢复功能。
🎯 主要特点
🔐 安全增强
- 完全隐藏机密信息: LLM隐藏主机名、密码和凭据
- 配置文件管理:仅使用预先配置的配置文件名进行服务器连接
- 安全认证:灵活支持密码/私钥认证
⚡ sudo完全解决问题
- 密码等待挂起:完全解决
- 自动修正机能: sudo自动将命令转换为安全形式
- NOPASSWD対応:与环境无关的稳定动作
🔄 会话恢复功能
- 自动复旧:超过30秒的自动会话恢复
- 强制再接続:复旧失败时の自动再接続
- 长时间处理对应:稳定执行批处理等
🌏 完整的日语对应
- 字符编码: UTF-8完全支持
- 特殊文字処理:正确处理感叹号等
- 日志和错误:支持日语留言
📊 MCP準拠
- 协议版本:2024-11-05完全准据
- JSON-RPC 2.0:规范通信
- 工具:全面SSH操作工具组
- 资源:配置文件信息和最佳实践
📋 系统要求
- python: 3.8以上
- 操作系统:Windows/Linux/macOS
- MCP主机: Claude Desktop、其他MCP支持的客户端
🚀 安装和安装
1.克隆存储库
git clone https://github.com/your-org/mcp-ssh-server.git
cd mcp-ssh-server
2.创建和启用虚拟环境
python -m venv venv
# Windows
venv\Scripts\activate
# Linux/macOS
source venv/bin/activate
3.安装相关性
pip install -r requirements.txt
4. SSH 配置文件设置
src/ssh_profiles.json 编辑并设置目标服务器信息:
{
"profiles": {
"production-web": {
"hostname": "prod-web.company.com",
"username": "webadmin",
"password": "your_password",
"port": 22,
"sudo_password": "your_sudo_password",
"private_key_path": null,
"description": "本番Webサーバー",
"auto_sudo_fix": true,
"session_recovery": true,
"default_timeout": 600.0
},
"development": {
"hostname": "192.168.1.100",
"username": "devuser",
"password": null,
"port": 2222,
"sudo_password": "dev_sudo_pass",
"private_key_path": "/path/to/dev_key.pem",
"description": "開発環境",
"auto_sudo_fix": true,
"session_recovery": true,
"default_timeout": 300.0
}
},
"default_profile": "development",
"profile_metadata": {
"version": "1.0",
"last_updated": "2025-01-25T10:00:00Z",
"created_by": "admin"
}
}
5. MCP添加设置
Claude Desktop等的MCP在设置中添加:
{
"mcpServers": {
"ssh-command-server": {
"command": "/path/to/mcp-ssh-server/venv/Scripts/python.exe",
"args": [
"/path/to/mcp-ssh-server/src/mcp_ssh_server_profile.py",
"--debug",
"--log-file",
"/path/to/mcp-ssh-server/log/ssh-command-server-debug_log.txt"
],
"env": {
"PYTHONUTF8": "1",
"PYTHONPATH": "/path/to/mcp-ssh-server",
"PYTHONUNBUFFERED": "1"
}
}
}
}
🔧 可用工具
📡 接続管理
ssh_connect_profile:使用配置文件建立安全连接ssh_list_profiles:可用配置文件浏览ssh_profile_info:获取配置文件详细信息ssh_disconnect: SSH断开连接ssh_list_connections:确认当前连接状态
⚡ 命令执行
ssh_execute:执行单个命令(带sudo自动修改)ssh_execute_batch:批量执行多个命令- **
ssh_analyze_command**单击功能区上sudo使用情况分析
🔧 診断・復旧
ssh_test_sudo: sudo测试配置ssh_recover_session:手动执行会话恢复
📚 信息资源
ssh://best-practices/full:完整最佳实践指南ssh://best-practices/profile-usage:使用配置文件ssh://connections:当前连接状态ssh://profiles:配置文件列表
💡 基本用法
1.确认配置文件列表
ssh_list_profiles()
2.建立安全连接
ssh_connect_profile(
connection_id="prod1",
profile_name="production-web"
)
3.命令执行(sudo自动修正)
ssh_execute(
connection_id="prod1",
command="sudo systemctl status nginx"
)
4.统一执行多个命令
ssh_execute_batch(
connection_id="prod1",
commands=[
"uptime",
"sudo ps aux | grep nginx",
"df -h"
]
)
🔐 安全功能
配置文件管理安全性
- 隐藏机密信息:请输入主机名、密码和凭据LLM完全隐藏
- 配置文件标识:仅使用安全标识符连接服务器
- 配置文件保护:适当的权限设置(600推荐)
sudo自动解决问题
- 密码等待挂起:完全解决
- 自动修正:
sudo→echo 'password' | sudo -S - NOPASSWD対応:
sudo→sudo -n - 设定确认:
ssh_test_sudo可测试
会话恢复
- 自动复旧:超过30秒时自动运行
- 中断信号: Ctrl+C等恢复
- 强制再接続:复旧失败时の自动再接続
📊 性能标准
- 配置文件导入: 0.1秒未満
- 常规命令: 1.0-1.1秒
- sudo命令:1.0-1.2秒(包括自动修复)
- 复杂管道: 1.0-1.3秒
- 会话恢复: 1-3秒
🚨 故障排除
常见问题
1.配置式连接失败
# プロファイル設定確認
ssh_profile_info("profile_name")
# 接続テスト
ssh_test_sudo("connection_id")
2. sudo权限错误
# sudo設定テスト
ssh_test_sudo("connection_id")
# 手動セッション復旧
ssh_recover_session("connection_id")
3.特殊字符错误
# シングルクォート使用
echo 'Special chars: !@#$%^&*()'
# 日本語は問題なし
echo "こんにちは世界"
检查日志
# デバッグログの確認
tail -f log/ssh-command-server-debug_log.txt
# エラーレベルのみ
grep ERROR log/ssh-command-server-debug_log.txt
🔄 传统迁移
旧方式(非推奨)
ssh_connect(
connection_id="server1",
hostname="192.168.1.100", # 機密情報露出
username="user",
password="password",
sudo_password="sudo_pass"
)
新方式(推奨)
ssh_connect_profile(
connection_id="server1",
profile_name="development-server" # 安全な識別子のみ
)
📚 详细文档
🤝 貢献
欢迎普尔请求和伊修的报告。
📄 许可证
MIT许可证
📞 支持
- 问题: GitHub Issues 问题报告
- 讨论:使用问题和讨论
- 文档:
src/best_practice.md详细信息
🔖 版本历史记录
v2.0.0(当前)
- 通过配置文件管理隐藏机密信息
- sudo完全解决问题
- 会话恢复功能
- 日本语完全对应
- MCP 2024-11-05准据
v1.x.x
- 基本的SSH连接功能
- 执行传统命令
🎯 LLM提示
这个服务器LLM的规格化距离的幂函数
- 安全:仅连接配置文件名称,无需敏感信息
- 自动修正: sudo可直接执行命令
- 复旧机能:自动解决会话问题
- 日本语对应:编码无问题
- 总括工具: SSH提供操作所需的全部功能
详细的使用方法是 ssh://best-practices/full 请参见资源。
