# SSH Command

> Execute commands on remote server via SSH.

Source: https://docs.sommatic.ai/en/nodes/io.ssh/

- Slug: `io.ssh`
- Family: Input and output
- Version: 1.0.0
- Status: Available
- Execution: async

Execute commands on remote server via SSH.

## Configuration

- `connection_id` (string, required): Credential for the SSH target. Accepts credentials of type `basic-auth` (username + password + host), `certificate` (username + private key), or `object` (advanced SSH config).
- `command` (string, required): Shell command to execute

## Output ports

- `out` (default): Command stdout
- `error`: Command stderr or connection failure

## Input contract

- `connection_id` (string, required)
- `command` (string, required)

## Output contract

- `stdout` (string, optional)
- `code` (number, optional)
- `signal` (string, optional)

## In expressions

What a later node can read from this node's output with `$("SSH Command").item.json.<path>` (write your node's label instead of `SSH Command`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("SSH Command").item.json.stdout` (string) = `"Filesystem  Size  Used Avail Use%\n/dev/sda1…"`
- `$("SSH Command").item.json.code` (number) = `0`
- `$("SSH Command").item.json.signal` (string) = `null`


## How it works

Opens an SSH session with a credential, runs one command on the remote host and returns its output and exit code.

1. Resolves the config. `connection_id` and `command` fall back to the same keys of the incoming payload; both are required.
2. Resolves the credential: `host` and `port` (default 22) from its config; `username`, `password`, `privateKey` and `passphrase` from its secret.
3. Connects, runs `command` in an exec channel and collects stdout and stderr until the channel closes.
4. Exit code 0 leaves through `out` with `{ stdout, code, signal }`; any other code through `error` with `{ stdout, stderr, code, signal }`.

## In a workflow

### Node

```json
{
  "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 /"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "stdout": "Filesystem  Size  Used Avail Use%\n/dev/sda1    50G   21G   27G  44%\n",
    "code": 0,
    "signal": null
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

The remote command exited with code 0. stderr is not included on this port.

```json
{
  "stdout": "Filesystem  Size  Used Avail Use%\n/dev/sda1    50G   21G   27G  44%\n",
  "code": 0,
  "signal": null
}
```

### `error`

The command exited non-zero (data is `{ stdout, stderr, code, signal }`), or the connection, authentication or exec channel failed (data is `{ error }`).

```json
{
  "stdout": "",
  "stderr": "systemctl: unit not found\n",
  "code": 5,
  "signal": null
}
```

## Behaviour in the code

- `connection_id`: Accepts `basic-auth` (username + password), `certificate` (username + `privateKey`, optional `passphrase`) or `object` credentials, with `host` and `port` in the config. A JSON value `{ host, port, username, password, privateKey, passphrase }` is accepted in place for local tests.
- `command`: Executed by the remote user's shell exactly as written after expressions are resolved.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `All configured authentication methods failed` | `error` | The server rejected the user, password or private key of the credential. |
| `Timed out while waiting for handshake` | `error` | The host did not answer the SSH handshake. Check `host`, `port` and that the orchestrator can reach it. |
| `command is required` | `error` | No command in the config nor in the incoming payload (`connection_id is required` is the equivalent for the credential). |
| `connection_id parece una cadena cruda pero no es JSON válido: <value>` | `error` | `connection_id` starts with `{` or names a local host but is not valid JSON. Select a stored credential instead. |

## Notes and limits

- No command timeout: a command that never ends keeps the node waiting. The library waits about 20 s for the handshake.
- No pseudo-terminal is allocated, so interactive commands (prompts, `sudo` asking for a password) do not work.
- One connection per run, closed when the command ends. No retries.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "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
    }
  }
}
```

### config_schema

```json
{
  "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

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string"
    },
    "command": {
      "type": "string"
    }
  },
  "required": [
    "connection_id",
    "command"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "stdout": {
      "type": "string"
    },
    "code": {
      "type": "number"
    },
    "signal": {
      "type": "string"
    }
  }
}
```

### ports

```json
[
  {
    "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
  }
]
```
