ssh
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseexec: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.jsonjson
{
"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: (required), (default 22), (required), OR + optional .
hostportusernamepasswordkeyPathpassphrase创建文件:
~/.claude/ssh-targets.jsonjson
{
"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"
}
}字段说明:(必填)、(默认22)、(必填), 或 + 可选的。
hostportusernamepasswordkeyPathpassphraseUsage
使用方法
exec:ssh
<shell command>Target a named host with on the first line:
@nameexec:ssh
@prod
sudo systemctl restart myappMulti-line scripts work:
exec:ssh
cd /var/log && tail -20 syslogexec:ssh
<shell command>在第一行使用指定命名主机:
@nameexec:ssh
@prod
sudo systemctl restart myapp支持多行脚本:
exec:ssh
cd /var/log && tail -20 syslogProcess 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 before reusing a unit name, or use a unique timestamped name:
systemctl reset-failed <unit>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 npm package. Install in :
ssh2~/.claude/gm-toolsexec:bash
cd ~/.claude/gm-tools && npm install ssh2The plugin searches: , , then global.
~/.claude/gm-tools/node_modules/ssh2~/.claude/plugins/node_modules/ssh2需要 npm包。在目录中安装:
ssh2~/.claude/gm-toolsexec:bash
cd ~/.claude/gm-tools && npm install ssh2插件会按以下顺序查找:、,然后是全局环境。
~/.claude/gm-tools/node_modules/ssh2~/.claude/plugins/node_modules/ssh2