# SSH connection failed

**URL:** <https://community.n8n.io/t/ssh-connection-failed/28554>\
**Category:** Questions\
**Tags:** ssh\
**Created:** [July 25, 2023, 6:24pm UTC](https://community.n8n.io/t/ssh-connection-failed/28554 "2023-07-25T18:24:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JanMrlth1](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/janmrlth1/32/3307_2.png) [@JanMrlth1](https://community.n8n.io/u/JanMrlth1)\
**Post date:** [July 25, 2023, 6:24pm UTC](https://community.n8n.io/t/ssh-connection-failed/28554/1 "2023-07-25T18:24:51Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![JanMrlth1](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/janmrlth1/32/3307_2.png) [@JanMrlth1](https://community.n8n.io/u/JanMrlth1)\
**Post date:** [July 25, 2023, 6:41pm UTC](https://community.n8n.io/t/ssh-connection-failed/28554/3 "2023-07-25T18:41:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [July 26, 2023, 4:41pm UTC](https://community.n8n.io/t/ssh-connection-failed/28554/4 "2023-07-26T16:41:06Z")

</div>

Hey @JanMrlth1,

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

---

<div class="post-metadata">

**Author:** ![JanMrlth1](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/janmrlth1/32/3307_2.png) [@JanMrlth1](https://community.n8n.io/u/JanMrlth1)\
**Post date:** [July 26, 2023, 7:50pm UTC](https://community.n8n.io/t/ssh-connection-failed/28554/5 "2023-07-26T19:50:08Z")

</div>

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. ✌

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

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

```

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [July 27, 2023, 8:45am UTC](https://community.n8n.io/t/ssh-connection-failed/28554/6 "2023-07-27T08:45:29Z")

</div>

Hey @JanMrlth1,

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [October 25, 2023, 8:45am UTC](https://community.n8n.io/t/ssh-connection-failed/28554/7 "2023-10-25T08:45:41Z")

</div>

Closed on October 25, 2023, 8:45am UTC

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