Cannot parse privateKey: Unsupported key format

George Zhang picture George Zhang · Nov 20, 2018 · Viewed 13.1k times · Source

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?

Answer

Dozon Higgs picture Dozon Higgs · Jan 1, 2019

Had the same problem, found the solution here.

basically use the PEM option when you create your key:

ssh-keygen -m PEM -t rsa