Cannot parse privateKey: Unsupported key format
Asked Answered
C

2

21

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?

Centre answered 20/11, 2018 at 19:57 Comment(5)
I found this issue in github.com/mscdex/ssh2-streams/issues/100 . Anyone have any idea to fall back the ssh-keygen to old version?Centre
what parameters did you use for ssh-keygen ?Hierocracy
I tried "-o " and almost all combinations already. But it still use OPENSSH in the header. For now, I just copied the old private key for the SSH2.Centre
the thing is, you shouldn't be using -o. See this article tutorialinux.com/convert-ssh2-opensshHierocracy
For updates w.r.t to node-ssh module refer this: #30367106Mcgray
V
24

Had the same problem, found the solution here.

basically use the PEM option when you create your key:

ssh-keygen -m PEM -t rsa 
Vivianne answered 1/1, 2019 at 11:41 Comment(0)
S
13

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)

Sanson answered 6/1, 2020 at 11:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.