SSH connection failed

Hi there,

I am not able to get my ssh credentials running.
I have created an ed25519 key-pair. As that did not work, I also created a RSA pair.
Both work from other machines. both trow this error:

Error message

Couldn’t connect with these settings
SSH connection failed: Cannot read properties of undefined (reading ‘replace’)

Stack

TypeError: Cannot read properties of undefined (reading 'replace')
    at sanitizePrivateKey (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Ssh/Ssh.node.js:27:51)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Ssh/Ssh.node.js:329:55)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:646:28)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:631:53

Please share your workflow

stuck a credential level

Information on your n8n setup

  • the latest and greatest: n8n version:1.0.5
  • Docker-Compose deployment with postgres:11 and n8nio/n8n

When I updated from 0.2xxx to 1.04 I had a prpblem with the encryption key. I read it from the config, added it to the .env and added - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY} in the docker-compose environment. I was able to unlock my credentials then.
I recreated the SSH-cred just in case. No effect.

I commented the line #command: /bin/sh -c “sleep 5; n8n start” because it trew an error when I was starting after the update to 1.0.4.

Thank you for your help!

Cheers
Jan

I looked into the function sanitizePrivateKey

I ‘sanatized’ the private key myself by not including
‘-----BEGIN OPENSSH PRIVATE KEY-----’ and
‘-----END OPENSSH PRIVATE KEY-----’

with those lines everything worked fine.

2 Likes

Hey @JanMrlth1,

So in this case what was the issue? Had you modifed the key before putting it into n8n?

I only copied the “bodySshKey” of the key. So the function was not able to split at ‘-----’.

My fault.

I guess

“-----BEGIN OPENSSH PRIVATE KEY-----”

and

“-----END OPENSSH PRIVATE KEY-----”

is just part of the private key. :v:

function sanitizePrivateKey(privateKey: string) {
	const [openSshKey, bodySshKey, endSshKey] = privateKey
		.split('-----')
		.filter((item) => item !== '');

	return `-----${openSshKey}-----\n${bodySshKey.replace(/ /g, '\n')}\n-----${endSshKey}-----`;
}
1 Like

Hey @JanMrlth1,

You got it, So we typically expect the full private key rather than just part of it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.