Unable to use SSH Credentials. Bug?

My setup:
Cloud based docker setup, n8n 0.126.1

Issue:
Error when using SSH (Private key based) Credential

Error: Cannot parse privateKey: Encrypted PPK private key detected, but no passphrase given
    at Client.connect (/usr/local/lib/node_modules/n8n/node_modules/ssh2/lib/client.js:243:13)
    at /usr/local/lib/node_modules/n8n/node_modules/node-ssh/lib/cjs/index.js:193:24
    at new Promise (<anonymous>)
    at NodeSSH.connect (/usr/local/lib/node_modules/n8n/node_modules/node-ssh/lib/cjs/index.js:173:15)
    at async Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Ssh/Ssh.node.js:300:17)
    at async /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:424:47

Passphrase is filled in correctly and is verified as it works fine with Putty/Filezilla.

There is an issue open in GitHub that seems to be related this. Will have a look.

1 Like

Ok, the issue got fixed. Can you please test it out locally and let me know if it works for you.

Fix got released with [email protected]

1 Like

Thanks for updating the node!

The credentials are finally able to work.

I have come across another obstacle though.
Can’t download a file using the SSH node:

{
  "nodes": [
    {
      "parameters": {
        "authentication": "privateKey",
        "resource": "file",
        "operation": "download",
        "path": "/root/Dockerfile"
      },
      "name": "SSH1",
      "type": "n8n-nodes-base.ssh",
      "typeVersion": 1,
      "position": [
        -350,
        160
      ],
      "credentials": {
        "sshPrivateKey": "DO SSH"
      }
    }
  ],
  "connections": {}
}

whereas, if i implement the same thing using the Function node, by using the same SSH library ( node-ssh), it works:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "const {NodeSSH} = require('node-ssh');\nconst ssh = new NodeSSH();\n\nconst credentials = $json;\n\nconst {connection} = await ssh.connect({\n  host: credentials.host,\n  port: 22,\n  username: 'root',\n  privateKey: credentials.key,\n  passphrase: credentials.passphrase\n});\n\nlet res = await ssh.getFile('/data/temp_Dockerfile', '/root/Dockerfile').then(function(Contents) {\n    console.log(\"The File's contents were successfully downloaded\");\n  }, function(error) {\n    console.log(\"Something's wrong\");\n    console.log(error);\n  });\n\nreturn items;"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        -670,
        -70
      ]
    }
  ],
  "connections": {}
}

Kindly advise regarding this.
Thanks again.

To be able to help you we need some additional information. Can you please tell us exactly the problem you are having and provide as much detail as possible? If you want to download a file what happens exactly? Does the node fail? If so, with what error? Does it crash? Does nothing happen at all? Is a file downloaded but the data invalid? …?
Because for me all is working perfectly fine.

Ah, my bad, forgot to include the error details.

The node fails with the following error:

Stack

Error: EACCES: permission denied, open '/tmp/prefix--7-AV1GxgHkzhr6'

Also, commands are executing fine.
Example, the command cat /root/Dockerfile produces the contents of the file as the output, as expected, but trying to download the doesn’t work.

How do you run n8n?

The SSH node has to download the file to a temp location first and then read it in again (that is sadly how the library works). It seems like that the user n8n runs with does maybe have a permission issue with writing to the /tmp folder. Can you check if giving the user full access will solve that problem?

My setup is Docker based.

Should i map an additional /tmp volume in docker to achieve this?

I’m not sure how to change the n8n user’s permission, in this case.

Update:
I tried by mapping a new volume in the n8n container:

    volumes:
      - ./tmp:/tmp

Still getting the permission error.

Note: I also tried to verify user permissions by creating a new file, touch /tmp/new.txt, from the ‘Execute Command’ node, and was successful in doing so.

Hi @jan, any idea about this?

Did just try to reproduce the issue you face. After I tried to download a file with the default Docker image, instead of my normal default development environment, I did run into the exact same problem. I could identify the problem and fixed it. Will try to release a new version today or tomorrow with that fix. Will update you here once it is available.

1 Like

Fix got released with [email protected]

Awesome, thanks!