ssh

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

exec:ssh — Remote SSH Execution

exec:ssh — 远程SSH执行

Runs shell commands on a remote host over SSH. No shell open, no manual connection — just write the command.
通过SSH在远程主机上执行Shell命令。无需打开Shell、无需手动连接——只需输入命令即可。

Setup

配置

Create
~/.claude/ssh-targets.json
:
json
{
  "default": {
    "host": "192.168.1.10",
    "port": 22,
    "username": "pi",
    "password": "yourpassword"
  },
  "prod": {
    "host": "10.0.0.1",
    "username": "ubuntu",
    "keyPath": "/home/user/.ssh/id_rsa"
  }
}
Fields:
host
(required),
port
(default 22),
username
(required),
password
OR
keyPath
+ optional
passphrase
.
创建
~/.claude/ssh-targets.json
文件:
json
{
  "default": {
    "host": "192.168.1.10",
    "port": 22,
    "username": "pi",
    "password": "yourpassword"
  },
  "prod": {
    "host": "10.0.0.1",
    "username": "ubuntu",
    "keyPath": "/home/user/.ssh/id_rsa"
  }
}
字段说明:
host
(必填)、
port
(默认22)、
username
(必填),
password
keyPath
+ 可选的
passphrase

Usage

使用方法

exec:ssh
<shell command>
Target a named host with
@name
on the first line:
exec:ssh
@prod
sudo systemctl restart myapp
Multi-line scripts work:
exec:ssh
cd /var/log && tail -20 syslog
exec:ssh
<shell command>
在第一行使用
@name
指定命名主机:
exec:ssh
@prod
sudo systemctl restart myapp
支持多行脚本:
exec:ssh
cd /var/log && tail -20 syslog

Process Persistence

进程持久化

SSH sessions kill child processes on close. To keep a process running after the command returns:
exec:ssh
sudo systemctl reset-failed myunit 2>/dev/null; systemd-run --unit=myunit bash -c 'your-long-running-command'
Always call
systemctl reset-failed <unit>
before reusing a unit name, or use a unique timestamped name:
exec:ssh
systemd-run --unit=job-$(date +%s) bash -c 'nohup myprogram &'
Fallback if systemd unavailable:
exec:ssh
setsid nohup bash -c 'myprogram > /tmp/out.log 2>&1' &
SSH会话关闭时会终止子进程。要让进程在命令返回后继续运行:
exec:ssh
sudo systemctl reset-failed myunit 2>/dev/null; systemd-run --unit=myunit bash -c 'your-long-running-command'
重用单元名称前请务必调用
systemctl reset-failed <unit>
,或使用带时间戳的唯一名称:
exec:ssh
systemd-run --unit=job-$(date +%s) bash -c 'nohup myprogram &'
如果systemd不可用的替代方案:
exec:ssh
setsid nohup bash -c 'myprogram > /tmp/out.log 2>&1' &

Dependency

依赖

Requires
ssh2
npm package. Install in
~/.claude/gm-tools
:
exec:bash
cd ~/.claude/gm-tools && npm install ssh2
The plugin searches:
~/.claude/gm-tools/node_modules/ssh2
,
~/.claude/plugins/node_modules/ssh2
, then global.
需要
ssh2
npm包。在
~/.claude/gm-tools
目录中安装:
exec:bash
cd ~/.claude/gm-tools && npm install ssh2
插件会按以下顺序查找:
~/.claude/gm-tools/node_modules/ssh2
~/.claude/plugins/node_modules/ssh2
,然后是全局环境。