Search code examples
node.jsaws-lambdassh-keygenssh2

How to generate SSH-Key compatible to SSH2


I want to make an aws lambda function which connects to a server via ssh and private key authentication.

I am using the simple-ssh node module which uses the ssh2 module as base. I tried using OpenSSH and RSA format for generating a key pair but none of them worked.

The error message which is shown is always

Error: Cannot parse privateKey: Unsupported key format

Does anyone know the valid parameters for a ssh-keygen command which is compatible to the ssh2 node module?

Thanks in advance :)


Solution

  • Okay I have found the issue I had. I was saving the private key inside of an environment variable. The problem was that there were no line breaks and it seems like the parser needed this line breaks to understand the key. When I saved the key into a file and read it with require('fs').readFileSync it worked.

    The command I needed to get the key was the following:

    ssh-keygen -m PEM -t rsa -b 2048