mcp-ssh-persistent
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-ssh-persistent Check disk space on web-01 and list the five biggest directories."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-ssh-persistent
MCP server for Claude Code that keeps SSH connections open to named servers and supports streaming shells.
Features
Server aliases. Every tool takes
server: "<alias>". Host, user and key live in a localconfig.json, so they never appear in prompts. The first call to an alias connects lazily. A dropped connection reconnects once on the next call. Keepalive is 15 s × 3.Host-key pinning (TOFU). The first connect pins the server's
SHA256:fingerprint inknown-hosts.json. On a mismatch the server refuses to connect. You can also pre-setfingerprintper server in config.No secrets in the LLM context.
Config rejects any
passwordkey.Sudo uses a password stored in the OS credential store (Windows Credential Manager, macOS Keychain or Linux Secret Service). The model never sees or types it.
Logs and responses go through secret redaction.
Exact command completion. Stream shells use a unique prompt marker, so a write returns as soon as the command finishes. The server also detects input prompts.
Local path policy. Uploads and downloads only touch allowed directories. Key dirs and agent config are always denied.
Atomic remote writes. The server writes a temp file, keeps the mode and owner, then renames it over the target. Remote symlinks are followed.
Fast SFTP. Transfers use parallel
fastPut/fastGetover one cached SFTP channel per server.Bounded output. Exec output is capped: the first 20% and last 80% are kept, with a
[truncated N bytes]marker. Stream buffers are capped, and multi-byte UTF-8 characters are never split.Channel budget. Per-server limits stay below the default OpenSSH
MaxSessions 10. Extra exec calls wait in a queue instead of failing.
Related MCP server: SSH Remote MCP Server
Requirements
Node.js >= 18 (tested on 22 and 24;
npm testneeds >= 21).Windows, macOS or Linux.
sudosupport uses the OS credential store; on Linux it needs a running Secret Service daemon (e.g. gnome-keyring or KeePassXC), so headless servers usually lack it. Other tools work on any OS.bashon each remote server:ssh_exec sudo:truerunsbash -c, and stream shells assume a bash login shell.
Setup
Option A: npm (recommended)
Create
~/.mcp-ssh-persistent/config.jsonfrom config.example.json:add your aliases;
set
localPathRootsto your workspace dir(s). If you skip this, uploads and downloads outside the OS temp dir are rejected.
known-hosts.jsonandlogs/are created next to the config file. Set the env varMCP_SSH_CONFIGto use a config file somewhere else (a leading~/is expanded).Optional, for sudo: store the sudo password of a remote user in the OS credential store. A hidden prompt asks for the password:
npx -p mcp-ssh-persistent mcp-ssh-persistent-set-sudo-password <remote-username><remote-username>is theusernameof the alias. Add--deleteto remove it. Where it is stored:Windows: Credential Manager entry
mcp-ssh-persistent:sudo:<remote-username>.macOS: generic password in the login keychain, service
mcp-ssh-persistent, accountsudo:<remote-username>. Inspect it withsecurity find-generic-password -s mcp-ssh-persistent -a sudo:<remote-username>. Passwords with line breaks are rejected.Linux: Secret Service item, service
mcp-ssh-persistent, accountsudo:<remote-username>.
Register the server with Claude Code, e.g. in a project
.mcp.json:{ "mcpServers": { "ssh": { "command": "npx", "args": ["-y", "mcp-ssh-persistent"] } } }Restart Claude Code. Connect to each alias for the first time from a trusted network, because that first connect pins the host key.
Option B: git clone
Clone and install:
git clone https://github.com/vivusk/mcp-ssh-persistent.git cd mcp-ssh-persistent && npm install cp config.example.json config.jsonEdit
config.json(gitignored) as in option A. Aconfig.jsoninside the package dir takes precedence over~/.mcp-ssh-persistent/config.json.Optional, for sudo:
npm run set-sudo-password -- <remote-username>.Register with
"command": "node", "args": ["<path-to>/mcp-ssh-persistent/src/index.js"]and restart Claude Code.
macOS notes
To use a passphrase-protected key without prompts, set
useAgent: trueand runssh-add --apple-use-keychain ~/.ssh/<key>once to store the passphrase in the Keychain. The agent starts empty after each login, so load the key again withssh-add --apple-load-keychain(or letsshdo it viaAddKeysToAgent yes+UseKeychain yesin~/.ssh/config). launchd providesSSH_AUTH_SOCKto apps started from the GUI.Local path matching is case-insensitive, like the default APFS volume.
Upgrading from 1.x
2.0 is a breaking release: ssh_connect and ssh_reset_shell are gone, every tool takes server: "<alias>" from the config file, and passwords are no longer accepted in config.
config.json
{
"defaults": { "privateKeyPath": "<path-to-private-key>", "port": 22 },
"servers": {
"web": { "host": "203.0.113.10", "username": "deploy" },
"db": { "host": "203.0.113.20", "username": "root", "port": 2222, "fingerprint": "SHA256:<base64>" },
"lab": { "host": "203.0.113.30", "username": "ops", "useAgent": true }
},
"localPathRoots": ["<your-workspace-dir>"],
"localPathDeny": [],
"limits": { "maxOutputBytes": 102400, "maxReadFileBytes": 2097152, "streamBufferBytes": 524288, "maxStreams": 4, "maxConcurrentExec": 4 }
}Key | Meaning |
| Values merged into every server: |
| Accepts |
|
|
| Use ssh-agent. Reads |
| Extra allowed local roots for upload/download. |
| Extra denied local paths. A deny rule always wins over a root. Accepts |
| Output caps and channel budget (see below) |
Tools
All tools return plain text. bold marks required params.
Tool | Params | Purpose |
|
| Stateless command on an exec channel. Returns stdout, a |
|
| Opens a stateful shell (history disabled) bound to |
|
| Writes |
|
| Reads buffered output since the last read or write |
|
| Answers a pending |
|
| Sends Ctrl+C, then closes that stream's shell channel |
|
| SFTP upload. A |
|
| SFTP download to a |
|
| Atomic write of text content without shell escaping |
|
| Reads a text file and returns |
| none | Pooled sessions: alias, host, user, connected, fingerprint, streams |
|
| Closes one session or all of them |
Exec vs stream
Scenario | Tool |
One-off command, need exit code |
|
One-off command as root (non-root user) |
|
|
|
|
|
File transfer / edit |
|
Stream states
Every stream result ends with a footer line:
Footer | Meaning |
| Command finished, and the shell is back at its prompt |
| Exactly |
| Some other password prompt ( |
| A |
|
|
| Read only: no prompt yet |
| The stream channel closed |
If the stream buffer cap dropped bytes, the result also shows [truncated N bytes]. If a write found output nobody had read, it reports that output instead of discarding it.
sudo -s / other shells: a root shell started with sudo -s or su does not use the marker prompt. The server then falls back to a generic $/# prompt match after 300 ms of quiet. That works but is slower and less exact. Use sudo:true on ssh_exec when you can.
Sudo
Never put a password in any tool argument or command line. There are two supported paths:
ssh_execwithsudo: true. The server runssudo -S -k -p '<per-call random marker>' -- bash -c '<command>'. It writes the password only after sudo's own prompt appears. If the host needs no password (NOPASSWD), it writes nothing. Limits:the command's stdin is EOF, so interactive commands do not work;
refused when the alias user is
root, and refused together withpty: true;hosts with
Defaults requirettyreject it; use a stream instead;bashis required on the remote.
Stream +
ssh_sudo_auth. Type the command (sudo apt update\n) withssh_stream_write. If the footer showsawaiting_input(sudo), callssh_sudo_auth. sudo caches credentials, so read the footer first: when no prompt appeared, there is nothing to answer.
Residual risk: a program running in the stream as the session user can print an exact fake [sudo] password for <user>: or [sudo: authenticate] Password: line. The sudo-rs prompt names no user, so ssh_sudo_auth cannot tell whose password it asks for. After su <other-user> or ssh <other-host> inside the stream, a sudo-rs prompt there would still receive the alias user's password; do not call ssh_sudo_auth in such nested shells. Only call ssh_sudo_auth right after a command you typed yourself that starts with sudo.
Stream shells start with history disabled, so commands typed through the MCP server are not saved to ~/.bash_history.
Local path policy
local_path of ssh_upload and ssh_download is resolved with realpath. Path comparison is case-insensitive on macOS and Windows (case-sensitive on Linux); the deny names below (.claude, .git, .mcp.json, CLAUDE.md) match in any case on every OS. The path must lie under os.tmpdir() or a localPathRoots entry. The working directory is not a default root.
These paths are always denied, even inside a root:
the directory of every configured
privateKeyPath;~/.sshand~/.claude;this repo directory;
the config file and its
known-hosts.json;any path with a
.claudeor.gitsegment;any file named
.mcp.jsonorCLAUDE.md;every
localPathDenyentry.
Windows alternate data streams (file:stream) are rejected.
Channel budget
By default OpenSSH allows MaxSessions 10 channels per connection. Per server this tool uses:
up to
maxStreams(4) shell channels;1 cached SFTP channel;
up to
maxConcurrentExec(4) exec channels. More exec calls wait in a FIFO queue.
That makes 9 ≤ 10. If you raise the limits, raise MaxSessions in the server's sshd_config as well. The server logs a warning when the configured budget is above 10.
Troubleshooting
Error | Fix |
| The server key changed. Verify it out of band. If the change is legitimate, delete the entry named in the error (in |
| Windows: start the OpenSSH agent service and run |
| Add the dir to |
| The output cap was hit. Narrow the command ( |
| Stop an unused stream ( |
| Stop a stream first, or raise |
| Run |
| Unlock it ( |
| Linux: install and unlock a Secret Service keyring (gnome-keyring or KeePassXC). If the message says |
The server writes its log to logs/mcp-ssh.log (beside the config file), rotated at 1 MB and redacted.
Development
npm test # unit tests (node --test)
npm run smoke -- <alias> # live read-only smoke (writes only under /tmp/mcp-ssh-smoke-*)
npm run smoke:mcp -- <alias> # spawns the MCP server and drives it over stdioEnvironment variables:
Variable | Meaning |
| Path of the config file (leading |
| Windows only: |
| Tests only: |
CI (.github/workflows/test.yml) runs npm test on Ubuntu, macOS and Windows with Node 22 and 24; the macOS job sets MCP_SSH_TEST_KEYCHAIN=1.
License
MIT
Available Tools
12 toolsssh_disconnectB
Disconnect one server session, or all sessions when server is omitted.
Inputs: server.
ssh_downloadA
Download a remote file via SFTP (parallel fastGet to a .part file, then renamed over the target: no half files). Same local path policy as ssh_upload. Returns one line: path, bytes, ms.
Inputs: server (required), local_path (required), remote_path (required).
ssh_execA
Run a command on a server via an exec channel (stateless, fresh environment per call; connects lazily). Returns stdout, a "--- stderr ---" section only when stderr is non-empty, and [exit: N]. Output is capped (head+tail kept). Exit 1 is not flagged as an error. Use ssh_stream_* for stateful/interactive work.
Inputs: server (required), command (required), pty, sudo, +1 more.
ssh_read_remote_fileA
Read a remote text file via SFTP. Returns "# ( bytes)" then the raw content. Files above limits.maxReadFileBytes (default 2 MB) or binary files are refused (use ssh_exec with head/tail/sed -n, or ssh_download).
Inputs: server (required), remote_path (required).
ssh_statusB
Status of pooled SSH sessions (alias, host, user, connected, host-key fingerprint, streams).
Inputs: no named parameters.
ssh_stream_readB
Read buffered output of a stream since the last read/write. Footer [state: ...] shows prompt / awaiting_input(kind) / running.
Inputs: stream_id (required), clear, wait_ms.
ssh_stream_startA
Open a stateful interactive shell (own channel, history disabled) on a server, bound to stream_id; later stream calls use stream_id only. Optional command runs like ssh_stream_write but waits only 2000 ms by default, so long-running commands (tail -f, pm2 logs) return early with [state: timeout]. stream_id must be unique across servers; max 4 streams per server by default.
Inputs: server (required), stream_id (required), command, wait_ms.
ssh_stream_stopA
Stop one stream: sends Ctrl+C, then closes only the shell channel of that stream.
Inputs: stream_id (required).
ssh_stream_writeA
Write data verbatim to a stream shell (include a real newline to press Enter) and wait until the command finishes (shell prompt), an input prompt appears, or wait_ms elapses. Footer: [state: prompt | awaiting_input(sudo|password|confirm) | timeout]; timeout means the command may still run (use ssh_stream_read). Unread output from before the write is reported, not silently dropped.
Inputs: data (required), stream_id (required), wait_ms.
ssh_sudo_authA
Answer a pending sudo password prompt in a stream with the password stored in the OS credential store (Windows Credential Manager / macOS Keychain / Linux Secret Service); never pass it yourself. Only acts when the stream shows exactly "[sudo] password for :" or the sudo-rs prompt "[sudo: authenticate] Password:" (state awaiting_input(sudo)); other prompts (ssh, su, mysql, Password:) are refused and nothing is sent. Call it right after a command you typed that starts with sudo. Waits like ssh_stream_write.
Inputs: stream_id (required), wait_ms.
ssh_uploadA
Upload a local file to a server via SFTP (parallel fastPut). local_path must lie under os.tmpdir() or a configured localPathRoots dir; key dirs, ~/.ssh, ~/.claude, the MCP server repo/config and any .claude/.git dir, .mcp.json or CLAUDE.md are always refused. Returns one line: path, bytes, ms.
Inputs: server (required), local_path (required), remote_path (required).
ssh_write_remote_fileA
Write content to a remote file via SFTP (no shell escaping). Atomic: writes a temp file in the same dir, keeps the existing file mode/owner, then renames over the target. Falls back to an in-place write (with a warning) when the dir is not writable.
Inputs: server (required), content (required), remote_path (required), mode.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 12 tools
The set cleanly separates three modes of work: stateless exec (ssh_exec), stateful interactive shells (ssh_stream_*), and SFTP (ssh_upload/ssh_download/ssh_read_remote_file/ssh_write_remote_file). Descriptions explicitly steer between the closest pairs (exec vs stream_write, upload vs write_remote_file, read_remote_file vs download). The only real overlap is ssh_exec versus ssh_stream_start's optional command, which the 2000 ms timeout note clarifies but does not fully eliminate.
All twelve names use snake_case with a uniform ssh_ prefix and mostly verb-led forms (exec, start, read, write, stop, download, upload, disconnect). Minor deviations: ssh_status is a bare noun, and compound tails vary in ordering (write_remote_file vs upload, sudo_auth as noun+verb). Still highly predictable and readable.
Twelve tools is well within a healthy range and each maps to a distinct capability: exec, four stream lifecycle/IO operations, two transfer directions, two remote file read/write, sudo auth, plus status and disconnect. Nothing feels padded, and no obvious capability is crammed into an overloaded tool.
The surface covers connection pooling, exec, interactive shells with stop, bidirectional file transfer, exact-content remote writes, sudo escalation, and session inspection/teardown — a coherent lifecycle. Gaps are minor: no explicit directory listing, delete, or mkdir (workable via ssh_exec), and sudo auth only applies to stream prompts, not exec calls.
Maintenance
Related MCP Connectors
Scoped, audited SSH exec, sessions, and SFTP on your saved servers without exposing credentials
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Manage remote servers, SSH terminals, files, databases and proxies with scoped access and approvals.
Use your own Windows, Mac or Linux computer from ChatGPT, Claude, Cursor or Gemini CLI: run commands, read, write and search files, run long processes. Your computer only makes an outgoing connection (no open ports or VPN). Read-only mode, allowed folders, blocked commands and an action log keep you in control. Free plan available.
Related MCP Servers
- AlicenseAqualityAmaintenanceEnables Claude to manage multiple SSH connections, execute remote commands, and transfer files across servers. Supports secure authentication, default directories, sudo operations, and deployment automation with profiles for different project types.374,004 npm546MIT
- AlicenseAqualityCmaintenanceEnables SSH remote access to servers through Claude, allowing users to execute commands, transfer files via SFTP, and manage multiple remote connections using natural language.129MIT
- AlicenseNot gradedqualityNot gradedmaintenanceConnects Claude to remote servers via SSH to execute commands, manage files, and browse directories. It allows users to add, edit, and switch between multiple server configurations through natural language conversations.-
- AlicenseAqualityDmaintenanceEnables Claude to connect to servers via SSH, execute commands, transfer files, and manage connections through natural language.916 npm1MIT