SSH V2

Execute commands via SSH

Actions3

Overview

This node enables executing commands on a remote device via SSH (Secure Shell). It supports two connection types: using stored credentials or dynamic parameters provided at runtime. Users can authenticate either with a password or a private key (with optional passphrase). The primary operation for the "Command" resource is to execute a shell command remotely in a specified working directory.

Common scenarios include:

  • Automating server management tasks by running shell commands remotely.
  • Retrieving system information or logs from remote machines.
  • Triggering scripts or applications on remote devices as part of an automation workflow.

Example use case:

  • Running ls -la in a specific directory on a remote Linux server to list files and process the output within an n8n workflow.

Properties

Name Meaning
Connection Type Choose between using stored credentials ("Credentials") or providing connection details dynamically ("Dynamic Parameters").
Authentication Select authentication method: "Password" or "Private Key".
Host Hostname or IP address of the SSH server (required if using Dynamic Parameters).
Port Port number of the SSH server, default is 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" authentication).
Private Key Private key string for authentication (required if using Dynamic Parameters and "Private Key" authentication).
Passphrase Optional passphrase for the private key (used only with "Private Key" authentication).
Command The shell command to execute on the remote device.
Working Directory The directory on the remote device where the command will be executed (default is "/").

Output

The node outputs an array of JSON objects, each corresponding to an input item processed:

  • For the "Execute Command" operation, each output item contains:
    • stdout: Standard output of the executed command.
    • stderr: Standard error output of the command.
    • code: Exit code of the command.

Example output JSON structure:

{
  "stdout": "file1\nfile2\n",
  "stderr": "",
  "code": 0
}

No binary data is produced for this operation.

Dependencies

  • Requires an SSH server accessible from the n8n instance.
  • Needs either stored SSH credentials or dynamic SSH connection parameters.
  • Uses an internal SSH client library to establish connections and execute commands.
  • If using private key authentication, the private key must be properly formatted.

Troubleshooting

  • Connection failures: Errors like "SSH connection failed" usually indicate incorrect host, port, username, or authentication details. Verify credentials and network accessibility.
  • Invalid path errors: Using "" without "/" in paths (e.g., `"folder") is invalid. Use absolute paths or "~/"` to represent the home directory.
  • Authentication errors: Ensure the correct authentication method is selected and credentials match the server's requirements.
  • Command execution errors: If the command fails, check the stderr output for details. Also verify that the working directory exists and the user has permissions.
  • Timeouts or hanging: Network issues or firewall restrictions might block SSH connections.

To resolve most issues, double-check all connection parameters, authentication credentials, and command syntax.

Links and References

Discussion