让智能体通过 SSH 在远程服务器上执行命令,并上传、下载文件。
接入配置
选择客户端,复制配置,再按项目文档补齐环境变量。
claude mcp add ssh --env HOST='<HOST>' --env PORT='<PORT>' --env USERNAME='<USERNAME>' -- npx -y @fangjunjie/ssh-mcp-server --host '{{config.HOST}}' --port '{{config.PORT}}' --username '{{config.USERNAME}}' --password '{{config.PASSWORD}}'~/.codex/config.toml
[mcp_servers.ssh]
command = "npx"
args = ["-y", "@fangjunjie/ssh-mcp-server", "--host", "{{config.HOST}}", "--port", "{{config.PORT}}", "--username", "{{config.USERNAME}}", "--password", "{{config.PASSWORD}}"]
env = { HOST = "<HOST>", PORT = "<PORT>", USERNAME = "<USERNAME>" }
# codex mcp add ssh --env HOST='<HOST>' --env PORT='<PORT>' --env USERNAME='<USERNAME>' -- npx -y @fangjunjie/ssh-mcp-server --host '{{config.HOST}}' --port '{{config.PORT}}' --username '{{config.USERNAME}}' --password '{{config.PASSWORD}}'~/.cursor/mcp.json
{
"mcpServers": {
"ssh": {
"command": "npx",
"args": [
"-y",
"@fangjunjie/ssh-mcp-server",
"--host",
"{{config.HOST}}",
"--port",
"{{config.PORT}}",
"--username",
"{{config.USERNAME}}",
"--password",
"{{config.PASSWORD}}"
],
"env": {
"HOST": "<HOST>",
"PORT": "<PORT>",
"USERNAME": "<USERNAME>"
}
}
}
}.vscode/mcp.json
{
"servers": {
"ssh": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@fangjunjie/ssh-mcp-server",
"--host",
"{{config.HOST}}",
"--port",
"{{config.PORT}}",
"--username",
"{{config.USERNAME}}",
"--password",
"{{config.PASSWORD}}"
],
"env": {
"HOST": "<HOST>",
"PORT": "<PORT>",
"USERNAME": "<USERNAME>"
}
}
}
}~/.gemini/settings.json
{
"mcpServers": {
"ssh": {
"command": "npx",
"args": [
"-y",
"@fangjunjie/ssh-mcp-server",
"--host",
"{{config.HOST}}",
"--port",
"{{config.PORT}}",
"--username",
"{{config.USERNAME}}",
"--password",
"{{config.PASSWORD}}"
],
"env": {
"HOST": "<HOST>",
"PORT": "<PORT>",
"USERNAME": "<USERNAME>"
}
}
}
}claude_desktop_config.json
{
"mcpServers": {
"ssh": {
"command": "npx",
"args": [
"-y",
"@fangjunjie/ssh-mcp-server",
"--host",
"{{config.HOST}}",
"--port",
"{{config.PORT}}",
"--username",
"{{config.USERNAME}}",
"--password",
"{{config.PASSWORD}}"
],
"env": {
"HOST": "<HOST>",
"PORT": "<PORT>",
"USERNAME": "<USERNAME>"
}
}
}
}.trae/mcp.json
{
"mcpServers": {
"ssh": {
"command": "npx",
"args": [
"-y",
"@fangjunjie/ssh-mcp-server",
"--host",
"{{config.HOST}}",
"--port",
"{{config.PORT}}",
"--username",
"{{config.USERNAME}}",
"--password",
"{{config.PASSWORD}}"
],
"env": {
"HOST": "<HOST>",
"PORT": "<PORT>",
"USERNAME": "<USERNAME>"
}
}
}
}需要的环境变量
HOSTPORTUSERNAME
把占位值换成你自己的密钥;不要把密钥提交到代码仓库。