SSH Command
通过 SSH 在远程服务器上执行命令。
使用凭据建立 SSH 会话,在远程主机上执行一条命令,并返回其输出和退出码。
工作原理
- 解析配置。
connection_id和command缺失时回退到输入 payload 中的同名键;两者均为必填。 - 解析凭据:
host和port(默认 22)取自凭据配置;username、password、privateKey和passphrase取自密钥。 - 建立连接,在 exec 通道中执行
command,并收集 stdout 和 stderr,直到通道关闭。 - 退出码为 0 时以
{ stdout, code, signal }从out输出;其他退出码以{ stdout, stderr, code, signal }从error输出。
在工作流中
节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。
{
"node_id": "node-check-disk",
"label": "Check disk usage",
"operator_slug": "io.ssh",
"operator_version": "1.0.0",
"config": {
"connection_id": "pi-credential-xxxx",
"command": "df -h /"
}
}{
"ok": true,
"data": {
"stdout": "Filesystem Size Used Avail Use%\n/dev/sda1 50G 21G 27G 44%\n",
"code": 0,
"signal": null
},
"port": "out"
}配置
-
connection_idstring 必填 -
SSH 目标的凭据。接受 `basic-auth`(用户名 + 密码 + 主机)、`certificate`(用户名 + 私钥)或 `object`(高级 SSH 配置)类型的凭据。
-
commandstring 必填 -
要执行的 shell 命令
代码中的行为
除 schema 描述之外,实现代码对这些键的实际处理。
-
connection_id - 接受
basic-auth(用户名 + 密码)、certificate(用户名 +privateKey,可选passphrase)或object凭据,host和port写在凭据配置中。本地测试时也可就地使用 JSON 值{ host, port, username, password, privateKey, passphrase }。 -
command - 表达式解析后,由远程用户的 shell 按原样执行。
输出端口
out 默认 远程命令以退出码 0 结束。此端口不包含 stderr。
数据
{
"stdout": "Filesystem Size Used Avail Use%\n/dev/sda1 50G 21G 27G 44%\n",
"code": 0,
"signal": null
}error 命令以非零码退出(数据为 { stdout, stderr, code, signal }),或连接、认证、exec 通道失败(数据为 { error })。
数据
{
"stdout": "",
"stderr": "systemctl: unit not found\n",
"code": 5,
"signal": null
}在表达式中
后续节点可通过 $("SSH Command").item.json.<路径> 读取此节点输出中的内容(请把 SSH Command 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。
| 表达式 | Editor | Worker |
|---|---|---|
$("SSH Command").item.json.stdout | ||
$("SSH Command").item.json.code | ||
$("SSH Command").item.json.signal |
错误
| 消息 | 端口 | 原因与处理 |
|---|---|---|
All configured authentication methods failed | error | 服务器拒绝了凭据中的用户名、密码或私钥。 |
Timed out while waiting for handshake | error | 主机未响应 SSH 握手。请检查 host、port,并确认编排器可以访问该主机。 |
command is required | error | 配置和输入 payload 中都没有命令(凭据缺失时对应 connection_id is required)。 |
connection_id parece una cadena cruda pero no es JSON válido: <value> | error | connection_id 以 { 开头或指向本地主机,但不是有效 JSON。请改为选择已保存的凭据。 |
输入契约
-
connection_idstring 必填 -
commandstring 必填
输出契约
-
stdoutstring 可选 -
codenumber 可选 -
signalstring 可选
契约(JSON Schema)
与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。
{
"slug": "io.ssh",
"name": "SSH Command",
"category": "io",
"version": "1.0.0",
"description": "Execute commands on remote server via SSH.",
"capabilities": [
"ssh",
"infrastructure",
"linux"
],
"config_schema": {
"type": "object",
"properties": {
"connection_id": {
"type": "string",
"title": "SSH Credential",
"description": "Credential for the SSH target. Accepts credentials of type `basic-auth` (username + password + host), `certificate` (username + private key), or `object` (advanced SSH config).",
"ui_widget": "connection_picker",
"ui_options": {
"credential_types": [
"basic-auth",
"certificate",
"object"
],
"types": [
"ssh"
]
}
},
"command": {
"type": "string",
"description": "Shell command to execute"
}
},
"required": [
"connection_id",
"command"
]
},
"input_contract_schema": {
"type": "object",
"properties": {
"connection_id": {
"type": "string"
},
"command": {
"type": "string"
}
},
"required": [
"connection_id",
"command"
]
},
"output_contract_schema": {
"type": "object",
"properties": {
"stdout": {
"type": "string"
},
"code": {
"type": "number"
},
"signal": {
"type": "string"
}
}
},
"ports": [
{
"port_id": "out",
"label": "Output",
"description": "Command stdout",
"is_default": true,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Command stderr or connection failure",
"is_default": false,
"supports_condition": false
}
],
"execution_mode": "async",
"required_resources": [],
"compatible_worker_pools": [
"standard-io",
"infra"
],
"tags": [
"ssh",
"terminal",
"bash"
],
"is_stateful": false,
"publisher": {
"identity": "org_link_loom",
"profile": {
"name": "Link Loom",
"verified": true,
"url": "https://me.veripass.com/link-loom",
"logo_url": null
}
}
}{
"type": "object",
"properties": {
"connection_id": {
"type": "string",
"title": "SSH Credential",
"description": "Credential for the SSH target. Accepts credentials of type `basic-auth` (username + password + host), `certificate` (username + private key), or `object` (advanced SSH config).",
"ui_widget": "connection_picker",
"ui_options": {
"credential_types": [
"basic-auth",
"certificate",
"object"
],
"types": [
"ssh"
]
}
},
"command": {
"type": "string",
"description": "Shell command to execute"
}
},
"required": [
"connection_id",
"command"
]
}{
"type": "object",
"properties": {
"connection_id": {
"type": "string"
},
"command": {
"type": "string"
}
},
"required": [
"connection_id",
"command"
]
}{
"type": "object",
"properties": {
"stdout": {
"type": "string"
},
"code": {
"type": "number"
},
"signal": {
"type": "string"
}
}
}[
{
"port_id": "out",
"label": "Output",
"description": "Command stdout",
"is_default": true,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Command stderr or connection failure",
"is_default": false,
"supports_condition": false
}
]执行
- 执行方式
async- 有状态
- 否
- 凭据
- 在服务器端根据
connection_id解析,密钥不会进入工作流。 - 能力
sshinfrastructurelinux- 标签
sshterminalbash
说明与限制
- 命令没有超时限制:永不结束的命令会使节点一直等待。库对握手大约等待 20 秒。
- 不会分配伪终端,因此交互式命令(提示输入、需要密码的
sudo等)无法使用。 - 每次运行一个连接,命令结束后关闭。不会重试。
已对照编排器代码核实 · 31e874b · 2026-11-26