通用 SSH 远程控制
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"ssh": {
"args": [
"-y",
"@txcxgzs/ssh-mcp@0.14.3"
],
"command": "npx"
}
}
}
该服务需要配置环境变量:SSH_CREDENTIAL_SSH1、SSH_CREDENTIAL_SSH2、SSH_CREDENTIAL_SSH3
可用工具 (21 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
ssh_exec 8 个参数 需填 2 项
Execute a command on a remote host via SSH. The command is interpreted by the remote login shell — pipes, redirects, globs, and other shell metacharacters work as expected. Returns stdout, stderr, and exit code. Use `env` to set environment variables for this call without modifying the command string. Subject to SSH_MCP_COMMAND_WHITELIST / SSH_MCP_COMMAND_BLACKLIST if configured (policy is checked against the env-prefixed command).
必填参数:host、command
ssh_read_file 6 个参数 需填 2 项
Read a file from a remote host via SFTP.
必填参数:host、path
ssh_write_file 7 个参数 需填 3 项
Write content to a file on a remote host via SFTP. Creates or overwrites the file.
必填参数:host、path、content
ssh_upload 7 个参数 需填 3 项
Upload a local file to a remote host via SFTP.
必填参数:host、localPath、remotePath
ssh_download 7 个参数 需填 3 项
Download a file from a remote host to local filesystem via SFTP.
必填参数:host、remotePath、localPath
ssh_ls 6 个参数 需填 2 项
List files in a directory on a remote host via SFTP.
必填参数:host、path
ssh_stat 6 个参数 需填 2 项
Get metadata for a file or directory on a remote host via SFTP. Returns size, permissions (octal), uid/gid, mtime/atime, and type flags (isFile, isDirectory, isSymbolicLink). Use this instead of parsing `ls -la` output.
必填参数:host、path
ssh_mkdir 7 个参数 需填 2 项
Create a directory on a remote host via SFTP. Set `recursive: true` to create parent directories as needed (like `mkdir -p`). Existing intermediate dirs are tolerated; an existing leaf path is still an error.
必填参数:host、path
ssh_delete 6 个参数 需填 2 项
Delete a file or empty directory on a remote host via SFTP. Auto-detects the path type and calls the right SFTP op (unlink for files/symlinks, rmdir for empty dirs). Recursive directory delete is intentionally NOT supported -- for that, use ssh_exec with `rm -rf` explicitly so the destructive intent is visible in the tool trace.
必填参数:host、path
ssh_diagnose 2 个参数 需填 1 项
Diagnose SSH connectivity issues. Checks ssh-agent status, loaded keys, known_hosts, SSH config, and attempts a test connection. Use this BEFORE attempting SSH operations if you suspect connectivity issues, or AFTER a failed SSH operation to understand why it failed.
必填参数:host
ssh_agent_ensure
Ensure ssh-agent is running and reachable. Starts a new agent if needed and sets environment variables so subsequent SSH operations work. Use this FIRST when SSH operations fail with agent-related errors.
该工具无需必填参数,直接调用即可
ssh_key_list
List all SSH private keys in ~/.ssh/ with their type, fingerprint, and whether they are loaded in the agent. Use this to find which keys are available and which ones need to be loaded.
该工具无需必填参数,直接调用即可
ssh_key_load 1 个参数 需填 1 项
Load an SSH private key into the running agent. Ensures the agent is running first. Use this after ssh_key_list shows a key that is not loaded.
必填参数:keyPath
ssh_config_lookup 1 个参数 需填 1 项
Resolve the effective SSH configuration for a host. Shows hostname, user, port, identity files, proxy settings, and all other options from ~/.ssh/config. Use this to understand how SSH will connect to a host.
必填参数:host
ssh_known_hosts_fix 2 个参数 需填 1 项
Remove a stale host key from known_hosts and re-scan the host to add the current key. Use this when you see 'Host key verification failed' errors, typically after a server has been recreated or reprovisioned.
必填参数:host
ssh_test 2 个参数 需填 1 项
Quick connectivity test to an SSH host. Reports success/failure with timing and actionable error details. Lighter and faster than ssh_diagnose — use this for a quick check before running operations.
必填参数:host
ssh_git_check 2 个参数
Test Git-over-SSH authentication to a hosting provider (GitHub, GitLab, Bitbucket, etc). Verifies your SSH key is registered and working. Use this when git clone/pull/push fails with SSH errors.
该工具无需必填参数,直接调用即可
ssh_multi_exec 7 个参数 需填 2 项
Execute a command on multiple remote hosts in parallel. Returns results per host. Use this instead of calling ssh_exec multiple times — it's faster and shows results side by side. Subject to SSH_MCP_COMMAND_WHITELIST / SSH_MCP_COMMAND_BLACKLIST if configured (policy is checked once before fan-out).
必填参数:hosts、command
ssh_find 13 个参数 需填 2 项
Search for files on a remote host. Wraps the find command with structured parameters so you don't have to construct find syntax manually.
必填参数:host、path
ssh_tail 9 个参数 需填 2 项
Read the last N lines of a file on a remote host, optionally filtering by a grep pattern. Use this for reading log files instead of ssh_exec with manual tail/grep commands.
必填参数:host、path
ssh_service_status 7 个参数 需填 2 项
Check the status of a systemd service on a remote host. Returns whether it's active, its PID, uptime, and description. Use this instead of ssh_exec with systemctl.
必填参数:host、service
服务介绍
通用 SSH Remote MCP本项目 fork 自 YawLabs/ssh-mcp,增加服务端 SSH 凭据映射,并修复 ~/.ssh/known_hosts 父目录不存在时的初始化问题。
基于开源项目 YawLabs/ssh-mcp 提供的 Model Context Protocol SSH 能力。
核心实现及版权归原项目作者所有,本条目用于提供 ModelScope Hosted MCP 的标准 STDIO 托管配置。
功能
支持 AI 通过 MCP 对用户明确授权的 SSH 主机进行远程操作,包括:
- SSH 连接测试与诊断
- 执行远程 Shell 命令
- SSH 连接复用
- 文件与目录操作
- SSH/SFTP 相关操作
- SSH Key 与 known_hosts 诊断
动态连接
本 MCP 不预置固定 SSH 主机。
AI 在调用工具时可以动态提供:
- host:SSH 主机/IP
- port:SSH 端口,默认 22
- username:SSH 用户名
- password:SSH 密码
- privateKeyPath:私钥路径
因此同一个 MCP 实例可以用于不同的 SSH 主机及不同 SSH 端口。
ModelScope Hosted 配置
{
"mcpServers": {
"ssh": {
"command": "npx",
"args": [
"-y",
"@yawlabs/ssh-mcp@latest"
]
}
}
}