Overview
This node enables executing commands on a remote device via SSH (Secure Shell). It supports two connection methods: using stored credentials or dynamic parameters provided at runtime. Authentication can be done either with a password or a private key (with optional passphrase). The primary use case for the Command - Execute operation is to run shell commands remotely, which is useful for automation tasks such as managing servers, running scripts, retrieving system information, or triggering processes on remote machines.
Practical examples:
- Running a backup script on a remote Linux server.
- Checking disk usage or system status by executing commands like
df -hortop. - Deploying code by running git commands or build scripts remotely.
- Automating administrative tasks without manual SSH login.
Properties
| Name | Meaning |
|---|---|
| Connection Type | Choose how to provide connection details: - Credentials: Use stored credentials. - Dynamic Parameters: Provide connection info dynamically per execution. |
| Authentication | Method of authentication: - Password - Private Key (optionally with passphrase) |
| Host | Hostname or IP address of the SSH server (required if using Dynamic Parameters) |
| Port | Port number of the SSH server (default 22, required if using Dynamic Parameters) |
| Username | Username for SSH authentication (required if using Dynamic Parameters) |
| Password | Password for authentication (required if using Dynamic Parameters and Password auth selected) |
| Private Key | Private key string for authentication (required if using Dynamic Parameters and Private Key auth) |
| Passphrase | Passphrase for the private key, if applicable (optional) |
| Command | The shell command to execute on the remote device |
| Working Directory | The directory on the remote machine where the command will be executed (default "/") |
Output
The output is an array of JSON objects, each corresponding to an input item processed. For the Command - Execute operation, each output item contains:
stdout: The standard output from the executed command.stderr: The standard error output from the command.code: The exit code returned by the command.
Example output JSON structure:
{
"stdout": "command output here",
"stderr": "",
"code": 0
}
No binary data is produced in this operation.
Dependencies
- Requires an SSH server accessible from the n8n environment.
- Needs either stored credentials or dynamic parameters for SSH connection.
- Uses the
node-sshlibrary internally to manage SSH connections. - If using private key authentication, the private key must be properly formatted and optionally accompanied by a passphrase.
- No additional external services are required beyond the SSH server.
Troubleshooting
- Connection failures: Commonly caused by incorrect host, port, username, or authentication details. Verify all connection parameters and credentials.
- Authentication errors: Ensure the password or private key (and passphrase if used) are correct and have appropriate permissions.
- Invalid working directory: The working directory path must exist on the remote machine; otherwise, command execution may fail.
- Command errors: Errors in the command itself will appear in the
stderrfield. Check command syntax and permissions on the remote server. - Path starting with "~" issues: Paths starting with
~are expanded to the home directory. Invalid usage (e.g., just~without slash) will throw an error. - Resource cleanup: The node disposes of SSH connections after execution to avoid resource leaks.
If the node is set to continue on failure, errors for individual items will be included in the output JSON under an error property.