But the expression is not evaluated correctly.
If hardcode an ip inside the credential everything ist working as expected for the single host, so the provided sshkey can’t be the reason it’s not working.
I need to loop over a list of hosts and execute an ssh comannd on each host.
Error: All configured authentication methods failed at doNextAuth (/usr/local/lib/node_modules/n8n/node_modules/ssh2/lib/client.js:865:21) at tryNextAuth (/usr/local/lib/node_modules/n8n/node_modules/ssh2/lib/client.js:1082:7) at USERAUTH_FAILURE (/usr/local/lib/node_modules/n8n/node_modules/ssh2/lib/client.js:430:11) at 51 (/usr/local/lib/node_modules/n8n/node_modules/ssh2/lib/protocol/handlers.misc.js:408:16) at Protocol.onPayload (/usr/local/lib/node_modules/n8n/node_modules/ssh2/lib/protocol/Protocol.js:2059:10) at AESGCMDecipherNative.decrypt (/usr/local/lib/node_modules/n8n/node_modules/ssh2/lib/protocol/crypto.js:987:26) at Protocol.parsePacket [as _parse] (/usr/local/lib/node_modules/n8n/node_modules/ssh2/lib/protocol/Protocol.js:2028:25) at Protocol.parse (/usr/local/lib/node_modules/n8n/node_modules/ssh2/lib/protocol/Protocol.js:313:16) at Socket.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/ssh2/lib/client.js:775:21) at Socket.emit (node:events:518:28)
Information on your n8n setup
n8n version: 1.82.1
Database (default: SQLite): Postgres
n8n EXECUTIONS_PROCESS setting (default: own): Own
Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
You can’t use expressions for setting up credentials. If you wish to dynamically generate credentials, you’d have to use a node where you can add the relevant data from the inputs. Not sure if it’s possible for SSH.
Hi, any progress on this? I would say this is an absolutely essential feature. If I want to send commands to dozens of VMs, it can’t be the solution to add a credential entry for each VM. In my opinion, this makes the SSH functionality close to unusable, already on private environments.
For the Moment i ended Up creating ssh credentials for each VM resulting in a messy Workflow with Lots of ssh nodes. It works but isn`t really maintainable.
Don’t want this discussion to close automatically, but wanted to note that I am trying to accomplish the exact same thing (automate SSH commands to a group of servers).
This is frustrating in the SSH Credential scenario, where you have a key to SSH to multiple hosts and need to automate a task across dozens or even hundreds hosts. Isn’t that the whole point of using dynamic expressions, which appears to be an allowed capability in the SSH Credential’s ‘Host’ field. At the workflow node, it becomes essentially useless because its unreferenced. IMO this is a MAJOR BUG that needs to be fixed.
Use the “Execute Command” Node + External SSH Script (Best for Scale)
You can bypass n8n’s SSH credential limits by calling an external shell or Python script via the Execute Command node.
Create a reusable script that accepts the hostname as an argument.
Use the Execute Command node in n8n.
Pass in the {{$json["host"]}} (or similar) as an argument to that script.
Use a Shell Script with for Loop Outside n8n (Batch Mode)
If you’re hitting n8n’s limitations hard, shift the SSH logic outside of n8n entirely — and use n8n to trigger a script that loops over a list of hosts.
Example Script Logic:
bash
for host in host1 host2 host3; do
ssh -i /path/to/key user@$host "uptime"
done
Trigger that via n8n’s Execute Command node with parameters injected dynamically.