SSH (Dynamic)

Execute commands via SSH with dynamic credential data

Actions3

Overview

This node allows executing commands on a remote device via SSH using dynamically provided connection details. It supports authentication either by password or private key, and lets users specify the working directory for command execution.

Common scenarios include:

  • Automating server management tasks remotely.
  • Running scripts or commands on cloud instances or on-premise servers.
  • Integrating remote system operations into workflows without manual SSH login.

For example, you could use this node to restart a service on a remote Linux server by running sudo systemctl restart apache2 or to check disk usage with df -h.

Properties

Name Meaning
Host The IP address or hostname of the remote SSH server (e.g., 127.0.0.1).
Port The SSH port number to connect to (default is 22).
Username The username to authenticate as on the remote server.
Authentication Method of authentication: either "Password" or "Private Key".
Password The password for SSH authentication (used if Authentication is "Password").
Private Key The private key string used for SSH authentication (used if Authentication is "Private Key").
Passphrase Optional passphrase for the private key if it is encrypted.
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 "/").

Output

The node outputs an array of items corresponding to each input item processed. Each output item contains a json field with the result of the executed command:

  • stdout: The standard output from the command execution.
  • stderr: The standard error output from the command execution.
  • code: The exit code returned by the command.

Example output JSON structure:

{
  "stdout": "command output here",
  "stderr": "",
  "code": 0
}

No binary data is produced by this operation.

Dependencies

  • Requires the node-ssh library for SSH connections.
  • Uses temporary file handling utilities for some internal operations.
  • No external API keys are required; however, valid SSH credentials must be provided.
  • The node expects the remote host to be reachable over the network and SSH service running.

Troubleshooting

  • Invalid path errors: If the working directory path starts with ~ but not ~/, the node throws an error asking to replace ~ with the full home directory path.
  • Authentication failures: Incorrect username, password, or private key will cause connection errors. Verify credentials and ensure the private key format is correct.
  • Connection timeouts: Ensure the host and port are accessible from the n8n instance.
  • Command execution errors: Non-zero exit codes or stderr output indicate issues with the command itself. Check command syntax and permissions on the remote server.
  • Passphrase issues: If using a private key with a passphrase, ensure the passphrase is correctly provided.

To resolve errors, verify all connection parameters, test SSH access independently, and confirm command correctness.

Links and References

Discussion