Cannot parse privateKey: Unsupported key format

32.1k views Asked by At

In my Mac book pro with OS Majave, I used SSH-KEYGEN generate a new SSH key for node.js module SSH2. However, I got error message: Cannot parse privateKey: Unsupported key format

I validated the key with ssh command, it just works fine. But not with the node.js module SSH2.

In the private key file, the header is -----BEGIN OPENSSH PRIVATE KEY----- while the end is -----END OPENSSH PRIVATE KEY-----.

I checked module ssh2-streams keyParser.js. The regexp pattern RE_HEADER_OPENSSH_PRIV does not include my header. Can anyone help?

2

There are 2 answers

0
Dozon Higgs On

Had the same problem, found the solution here.

basically use the PEM option when you create your key:

ssh-keygen -m PEM -t rsa 
0
Arnaud Valle On

You could also convert your existing key, rather than create a new one (make sure you back it up before you run the following command as it will overwrite your original one):

ssh-keygen -p -m PEM -f ~/.ssh/id_rsa

(Original answer from https://serverfault.com/a/950686)