mcp-ssh
Enables SSH remote command execution, passwordless key management, Windows Session 0 desktop process launching, and SFTP file transfers across Windows, Linux, and macOS.
README
mcp-ssh
A production-grade Model Context Protocol (MCP) server for cross-platform SSH remote execution, automated passwordless key management, Windows Session 0 interactive desktop process launching, and SFTP file transfers.
How It Works
Agent (Claude / Antigravity / Custom Script)
│ stdio JSON-RPC (MCP Protocol)
▼
mcp-ssh Server (Node.js + TypeScript)
│ Native SSH2 / SFTP Streams
▼
Remote Target Machine
├─ Windows (Win32-OpenSSH, Base64 UTF-16LE, Session 0 Bypass, Administrators ACLs)
├─ Linux (OpenSSH, bash, ~/.ssh/authorized_keys)
└─ macOS (systemsetup remotelogin, zsh/bash)
The agent connects over standard stdio JSON-RPC. mcp-ssh encapsulates all platform matrix quirks, UTF-16LE PowerShell encoding, Session 0 Task Scheduler handoffs, 8,191-character command line walls, and key ACL permissions ngầm in code so the agent receives clean, predictable, structured JSON results.
Core Capabilities
- Zero Local Client Shell Dependencies: Written in pure TypeScript with
ssh2. Does not require WSL, Git Bash,sshpass,iconv, or localsshbinaries on Windows or macOS clients. - Automated PowerShell Command Encoding: Converts Windows command bodies to Base64 UTF-16LE strings (
powershell.exe -EncodedCommand), removing all nested quote escaping errors. - Session 0 Desktop Handoff (
desktop: true): Solves the classic Win32-OpenSSH issue where GUI apps launch invisibly in Session 0. Resolves owner of activeexplorer.exeand schedules a temporary Task Scheduler job withLogonType Interactiveto launch GUI apps on the user's active desktop (Session 1). - 8,191-Character Boundary Auto-Fallback: Automatically detects when encoded PowerShell payloads exceed the 8,000-character cmd.exe length limit wall, seamlessly uploading a UTF-8 BOM temporary script via SFTP and executing it with
powershell -File. - First-Connect & Key Lifecycle:
- Connection probe with target OS auto-detection.
- Generates OpenSSH RDP Bootstrap 1-liners when target SSH is uninstalled or port 22 is closed.
- Clears stale entries from
~/.ssh/known_hostswhen hosts are re-imaged (REMOTE HOST IDENTIFICATION HAS CHANGED). - Deploys
ed25519key pairs with OS-strict ACLs (icacls SYSTEM:F Administrators:Fon Windows;chmod 600on Unix). - Revokes key access or clears authorized keys via
ssh_remove_passwordless.
Quick Start
1. Build the MCP Server
cd claude/mcp-ssh
npm install
npm run build
2. Register with Claude Desktop / Claude Code
Claude Code CLI:
# Windows:
claude mcp add ssh -- node "C:/path/to/my_notes/claude/mcp-ssh/dist/index.js"
# macOS / Linux:
claude mcp add ssh -- node "/absolute/path/to/my_notes/claude/mcp-ssh/dist/index.js"
Claude Desktop Configuration (claude_desktop_config.json):
{
"mcpServers": {
"ssh": {
"command": "node",
"args": [
"/absolute/path/to/my_notes/claude/mcp-ssh/dist/index.js"
]
}
}
}
Tool Reference
ssh_test_connection
Probes SSH connectivity, authenticates, and auto-detects target OS (windows, linux, mac). If target port 22 is closed, outputs an OpenSSH RDP bootstrap script.
| Parameter | Type | Required | Description |
|---|---|---|---|
host |
string | Yes | Target hostname or IP address |
username |
string | Yes | SSH username |
password |
string | No | SSH password |
privateKeyPath |
string | No | Path to private key file |
port |
number | No | SSH port (default: 22) |
ssh_clear_known_hosts
Removes stale host key entries matching host from ~/.ssh/known_hosts to resolve host key collision errors.
| Parameter | Type | Required | Description |
|---|---|---|---|
host |
string | Yes | Hostname or IP to clear |
ssh_exec
Executes remote commands over SSH across Windows, Linux, and macOS.
| Parameter | Type | Required | Description |
|---|---|---|---|
host |
string | Yes | Target host IP or domain |
username |
string | Yes | SSH username |
command |
string | Yes | Command line or script body |
password |
string | No | SSH password |
privateKeyPath |
string | No | Path to private key file |
targetOs |
enum | No | auto (default), windows, linux, mac |
desktop |
boolean | No | Windows only: launch in Session 1 interactive GUI desktop (false default) |
session |
number | No | Windows only: force specific session ID |
port |
number | No | SSH port (default: 22) |
Response Format:
EXIT CODE: 0
--- STDOUT ---
WindowsProductName OsVersion OsArchitecture
------------------ --------- --------------
Windows 10 Enterprise 10.0.26200 64-bit
--- STDERR ---
(empty)
ssh_setup_passwordless
Generates an ed25519 key pair locally if missing, deploys public key to target host with strict ACLs, and verifies key login.
| Parameter | Type | Required | Description |
|---|---|---|---|
host |
string | Yes | Target host IP |
username |
string | Yes | Target username |
password |
string | Yes | Password required for initial key copy |
keyPath |
string | No | Private key path (defaults to ~/.ssh/id_ed25519) |
targetOs |
enum | No | auto (default), windows, linux, mac |
port |
number | No | SSH port (default: 22) |
ssh_remove_passwordless
Removes a specific public key entry or clears all public key entries from the target authorized keys file, revoking key-based login.
| Parameter | Type | Required | Description |
|---|---|---|---|
host |
string | Yes | Target host IP |
username |
string | Yes | Target username |
password |
string | No | SSH password |
privateKeyPath |
string | No | Private key path |
keyPathToRemove |
string | No | Local public key path to remove |
removeAllKeys |
boolean | No | Clear ALL authorized keys on target (false default) |
port |
number | No | SSH port (default: 22) |
ssh_upload_file / ssh_download_file
Uploads or downloads files over native SFTP streams.
| Parameter | Type | Required | Description |
|---|---|---|---|
host |
string | Yes | Target host IP |
username |
string | Yes | SSH username |
localPath |
string | Yes | Local file path |
remotePath |
string | Yes | Remote target path |
password |
string | No | SSH password |
privateKeyPath |
string | No | Private key path |
ssh_generate_rdp_bootstrap
Generates a self-contained 1-liner PowerShell script to paste into an RDP session to install Win32-OpenSSH, open firewall port 22, and set autostart services.
| Parameter | Type | Required | Description |
|---|---|---|---|
host |
string | No | Target host IP or hostname |
userType |
enum | No | admin (elevated) or user (triggers UAC prompt) |
Status & Verification
- TypeScript Compilation: Clean build (
npm run build, 0 errors). - Live Verification against Windows Host: Tested against live Windows 10 Enterprise target:
ssh_test_connection: Passed (connected, target OS auto-detected as WINDOWS).ssh_exec: Passed (Base64 UTF-16LE executedGet-ComputerInfo, exit code 0).ssh_exec(desktop: true): Passed (Session 1 task scheduled for activeexplorer.exeowner, executed and cleaned up without trace).
Security Model
- Trusted Local Engine: Designed for single-user internal developer and QA automation workflows.
- Credential Protection: Passwords and private keys remain in memory within the stdio MCP process during execution and are never logged to stdout or stored in command line histories.
- Strict Key Permissions: Automatically enforces OpenSSH ACL requirements on target machines (
SYSTEM:F+Administrators:Ffor Windowsadministrators_authorized_keys;chmod 600for Unixauthorized_keys).
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。