Skip to main content
Glama
SSH MCP Server

SSH MCP Server

by jiahuidegit

SSH MCP Server

GitHub Stars License: MIT Node.js npm version npm downloads

A secure remote server management tool based on MCP protocol, supporting SSH connections, command execution, and SFTP file transfers.

The only MCP SSH tool that truly prevents AI from accidentally running commands on the wrong server.

If you find this project helpful, please give it a star on GitHub! Your support helps us improve!

English | 中文


Why SSH MCP Server?

Managing remote servers with AI assistants is powerful -- but also dangerous. When multiple servers are connected, AI models frequently mix up which server they're operating on. One wrong rm -rf on a production server, and you're in trouble.

SSH MCP Server is built from the ground up to solve this problem. Every safety mechanism is enforced server-side with cryptographic tokens -- the AI cannot bypass them, no matter what.

Safety guarantees other tools don't have:

  • Target Lock -- Tracks which server the AI is currently operating on. If it tries to switch targets, it must confirm first. No silent mistakes.

  • Alias-based routing -- Save servers with aliases like us-prod or jp-staging, then use exec(alias: "us-prod") instead of raw IPs. Harder to mix up.

  • Dangerous command detection -- 60+ patterns covering Docker, Kubernetes, databases, system commands. All require cryptographic token confirmation.

  • Multi-connection enforcement -- When multiple servers are connected, every operation MUST specify the target. No ambiguous defaults.

  • Environment labels -- Mark servers as production / staging / test. Every command output shows which environment it ran on.


Related MCP server: MCP SSH Tools Server

Features

  • SSH Connection Management - Password/key authentication with connection pooling, private key supports both content and file path

  • Command Execution - Regular commands, sudo commands, batch execution, shell mode (bastion hosts)

  • SFTP Operations - Upload, download, list directories, create/delete files

  • Server Management - Save/list/remove server configurations with alias support

  • Credential Security - System Keychain encrypted storage (macOS/Windows/Linux)

  • Audit Logging - Records all operations with sensitive data masking

  • Persistent Shell Sessions - Multi-round interaction for bastion host scenarios

  • Target Lock Protection - Prevents AI from accidentally running commands on the wrong server


What's New

v0.8.1 (Latest)

  • Private Key File Path Support - privateKey parameter now accepts both key content and file paths

    • Previously you had to paste the entire key content; now you can just pass a path like /path/to/id_rsa.pem or ~/.ssh/id_rsa

    • Auto-detects format: -----BEGIN prefix = key content, otherwise treated as file path

    • Supports ~ home directory expansion

v0.7.0

  • Target Lock: Server Switch Protection - The core safety feature for multi-server scenarios

    • Tracks the AI's current operation target; switching servers requires explicit confirmation with a cryptographic token

    • Single server: zero overhead. Multi-server, same target: zero overhead. Only triggers on actual target switch.

    • Works across all tools: exec, exec_sudo, exec_shell, shell_send, and all SFTP operations

    • If both target switch and dangerous command confirmations are needed, they run in sequence (switch first)

  • Alias Support for All Tools - Use server aliases instead of raw host/port/username

    • exec(alias: "us-prod", command: "ls") -- routes to the saved server configuration

    • Available on all exec and SFTP tools via the new alias parameter

  • Server Environment Labels in All Outputs - Every command result now shows [Server: us-prod (root@1.2.3.4) | Env: PRODUCTION]

    • No longer limited to production only -- all environments are labeled

  • SFTP Multi-Connection Safety - SFTP operations now enforce the same multi-connection safety checks as command execution

    • SFTP results include server field with full identity information

  • Connect shows active connections - When connecting a second server, the response lists all active connections as a reminder

v0.6.0

  • Server Identity System - Commands return full server identity (host, port, username, environment, alias)

  • Confirmation Token Mechanism - Cryptographic tokens replace boolean flags; AI cannot forge confirmations

  • 60+ Dangerous Command Patterns - Docker, Kubernetes, databases, system services, Git, network, package managers

  • Multi-Connection Enforcement - Must specify target when multiple connections are active

v0.5.0

  • Persistent Shell Sessions - shell_send, shell_read, shell_close for multi-round bastion host interaction

View Full Changelog | All Releases


📦 Quick Start

npx @erliban/ssh-mcp-server

Option 2: Global Installation

npm install -g @erliban/ssh-mcp-server
ssh-mcp-server

Option 3: Build from Source

git clone https://github.com/jiahuidegit/ssh-mcp-server.git
cd ssh-mcp-server
npm install
npm run build

🔄 Update to Latest Version

npx automatically uses the latest version, just restart your MCP client:

# No manual update needed, npx always fetches latest
npx @erliban/ssh-mcp-server

If globally installed

# Update to latest version
npm update -g @erliban/ssh-mcp-server

# Or reinstall
npm install -g @erliban/ssh-mcp-server@latest

Check current version

npm list -g @erliban/ssh-mcp-server

🎮 MCP Client Configuration

This server supports all MCP-compatible clients. Here's an example with Claude Desktop:

Edit the configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "ssh": {
      "command": "npx",
      "args": ["-y", "@erliban/ssh-mcp-server"],
      "env": {
        "SSH_MCP_LOG_LEVEL": "info"
      }
    }
  }
}

For other MCP clients, please refer to their respective documentation for configuration methods.


⚙️ Environment Variables

Variable

Description

Default

SSH_MCP_LOG_LEVEL

Log level (debug/info/warn/error)

info

SSH_MCP_LOG_FILE

Log file path

stderr

SSH_MCP_CONN_TIMEOUT

Connection timeout (ms)

30000

SSH_MCP_CMD_TIMEOUT

Command timeout (ms)

60000

SSH_MCP_IDLE_TIMEOUT

Idle connection timeout (ms)

300000

SSH_MCP_MAX_CONNECTIONS

Maximum connections

10

SSH_MCP_DATA_DIR

Data directory

~/.ssh-mcp

SSH_MCP_MASTER_PASSWORD

Master password for file storage

-


🛠️ MCP Tools

Connection Management

Tool

Description

connect

Establish SSH connection (password/key auth)

disconnect

Disconnect specific or all connections

Server Management

Tool

Description

save_server

Save server configuration locally

list_servers

List saved servers (supports group filtering)

remove_server

Remove server configuration

Command Execution

Tool

Description

exec

Execute remote command (supports alias routing)

exec_sudo

Execute with sudo privileges

exec_batch

Batch execute on multiple servers

exec_shell

Execute via interactive shell (for bastion hosts)

shell_send

Send input to persistent shell session

shell_read

Read shell session output buffer

shell_close

Close persistent shell session

SFTP Operations

Tool

Description

sftp_ls

List directory contents (supports alias routing)

sftp_upload

Upload file

sftp_download

Download file

sftp_mkdir

Create directory

sftp_rm

Delete file or directory

System Tools

Tool

Description

health_check

Check connection status

get_logs

Get audit logs

list_active_connections

List all active connections with environment labels


💡 Usage Examples

Connect and Execute Command

User: Connect to 192.168.1.100 with username root and password 123456

Claude: [calls connect tool]
Connected to root@192.168.1.100:22

User: Check system load

Claude: [calls exec tool]
10:30:01 up 45 days, 2:15, 1 user, load average: 0.15, 0.10, 0.05

Upload Deployment File

User: Upload local /tmp/app.jar to server's /opt/app/

Claude: [calls sftp_upload tool]
Uploaded /tmp/app.jar -> /opt/app/app.jar

Batch Check Server Status

User: Check disk usage on all production servers

Claude: [calls list_servers, then exec_batch]
Server 10.0.0.1: 45% used
Server 10.0.0.2: 62% used
Server 10.0.0.3: 78% used ⚠️

Security Notes

  1. Target Lock - Tracks the AI's operation target; switching servers requires cryptographic token confirmation. Prevents the #1 cause of AI server misoperations.

  2. Credential Storage - Prefers system Keychain (macOS Keychain, Windows Credential Manager). Falls back to AES-256-GCM encrypted file storage when no desktop environment is available.

  3. Log Masking - Passwords, private keys, and other sensitive information are automatically masked.

  4. Dangerous Commands - 60+ patterns detected. All require token confirmation. Production environments get extra warnings.

  5. Connection Pool - Automatically cleans up idle connections to prevent resource leaks.

  6. Multi-Connection Safety - When multiple servers are connected, every operation must explicitly specify the target server.


📊 Star History


🤝 Contributing

Issues and Pull Requests are welcome!


📄 License

This project is licensed under the MIT License.


⭐ If you find this project helpful, please give it a star!

🤝 Feel free to open issues for questions or submit PRs for improvements!

Available Tools

20 tools
connectA

建立 SSH 连接。两种方式二选一:(1) 通过 alias 连接已保存的服务器;(2) 通过 host + username + password/privateKey 直接连接。使用 alias 时可额外传 password/privateKey 覆盖已存储的凭证。

Inputs: alias, host, port, username, +4 more.

disconnectC

断开 SSH 连接

Inputs: host, port, username, all.

execA

在远程服务器执行命令。必须指定目标服务器:使用 alias(推荐,需先 save_server)或使用已连接的 host。只有一个活跃连接时可省略目标。多服务器场景下切换目标时会要求确认。危险命令需要 confirmationToken。

Inputs: command (required), alias, host, port, +6 more.

exec_batchA

在多台服务器批量执行命令。批量操作风险极高!包含生产环境服务器时会有特别警告。危险命令需要 confirmationToken。

Inputs: command (required), servers (required), timeout, confirmationToken.

exec_shellA

通过交互式 shell 模式执行命令(用于堡垒机穿透等不支持 exec 的场景)。必须指定目标服务器:使用 alias(推荐)或 host。只有一个活跃连接时可省略目标。

Inputs: command (required), alias, host, port, +5 more.

exec_sudoA

以 sudo 权限执行命令。必须指定目标服务器:使用 alias(推荐)或 host。只有一个活跃连接时可省略目标。多服务器场景下切换目标时需确认。危险命令需要 confirmationToken。

Inputs: command (required), sudoPassword (required), alias, host, +6 more.

get_logsC

获取操作审计日志

Inputs: limit, server, operation, level.

health_checkB

检查 SSH 连接健康状态

Inputs: host, port, username.

list_active_connectionsA

列出当前所有活跃的 SSH 连接,包含服务器环境标签(production/staging/test/development)和别名信息,帮助 AI 识别当前连接的是哪些服务器

Inputs: no named parameters.

list_serversA

列出已保存的服务器配置

Inputs: group.

remove_serverA

删除已保存的服务器配置。删除任何服务器都需要先获取 confirmationToken,生产环境服务器会有特别警告。

Inputs: alias (required), confirmationToken.

save_serverA

保存服务器配置和凭证。覆盖现有配置时需要先获取 confirmationToken。强烈建议设置 environment 字段以防止误操作生产服务器。

Inputs: alias (required), host (required), username (required), authType (required), +8 more.

sftp_downloadA

从远程服务器下载文件到本地。使用 alias(推荐)或 host 指定目标服务器,单连接时可省略。

Inputs: remotePath (required), localPath (required), alias, host, +4 more.

sftp_lsA

列出远程目录内容。使用 alias(推荐)或 host 指定目标服务器,单连接时可省略。

Inputs: path (required), alias, host, port, +2 more.

sftp_mkdirA

在远程服务器创建目录。使用 alias(推荐)或 host 指定目标服务器,单连接时可省略。

Inputs: path (required), alias, host, port, +3 more.

sftp_rmB

删除远程文件或目录。使用 alias(推荐)或 host 指定目标服务器,单连接时可省略。

Inputs: path (required), alias, host, port, +3 more.

sftp_uploadA

上传本地文件到远程服务器。使用 alias(推荐)或 host 指定目标服务器,单连接时可省略。

Inputs: localPath (required), remotePath (required), alias, host, +4 more.

shell_closeA

关闭持久化 shell 会话。使用 alias(推荐)或 host 指定目标服务器,单连接时可省略。

Inputs: alias, host, port, username.

shell_readA

读取持久化 shell 会话的输出缓冲区。使用 alias(推荐)或 host 指定目标服务器,单连接时可省略。

Inputs: alias, host, port, username, +1 more.

shell_sendA

发送输入到持久化 shell 会话(用于多轮交互,如堡垒机穿透登录流程)。必须指定目标服务器:使用 alias(推荐)或 host。只有一个活跃连接时可省略目标。

Inputs: input (required), alias, host, port, +6 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 20 tools

    Disambiguation5/5

    Each tool has a distinct purpose: exec variants (single, batch, shell, sudo), SFTP operations (upload, download, list, etc.), session management (shell_*), and server configuration. Even similar-sounding tools like exec and exec_shell are clearly differentiated by interactive vs sudo mode.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern: exec_*, sftp_*, shell_*, list_*, etc. No mixing of styles (all lowercase with underscores). Even standalone verbs like 'connect' and 'disconnect' fit the pattern.

    Tool Count5/5

    Twenty tools is appropriate for an SSH management server. It covers connection, command execution, file transfer, session control, server configuration, and audit, without excessive redundancy.

    Completeness5/5

    The tool surface covers the full lifecycle of SSH operations: connect/disconnect, various execution modes, SFTP file management, persistent shell sessions, server config storage, health checks, and logs. Missing features like port forwarding are not core to typical SSH workflows.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      A server that enables remote command execution over SSH through the Model Context Protocol (MCP), supporting both password and private key authentication.
      1
      9 npm
      2
      MIT
    • F
      license
      A
      quality
      D
      maintenance
      A server based on the MCP framework that provides remote server management capabilities through SSH, supporting features like connection pooling, file transfers, and remote command execution.
      7
      -
    • A
      license
      A
      quality
      D
      maintenance
      An MCP server for SSH/SCP operations with passwordless authentication, enabling remote command execution, file transfer, and session management.
      19
      17 npm
      1
      MIT