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?
This way there is no Cannot parse privateKey error. Please use ssh-keygen -m PEM -t rsa -b 2048 to generate your keys (the PEM format is required). Additionally, when I didn't specify bits with the -b option Azure told me the key file was too long.
New keys with OpenSSH private key format can be converted using ssh-keygen utility to the old PEM format. There is no need to downgrade to older OpenSSH just to achieve this result. Some elaboration on the above answers to provide a clear path for both the public and private key.
Downgrade your ssh-keygen binary (you can easily get old version from any linux/docker image) Add option -m PEM into your ssh-keygen command. For example, you can run ssh-keygen -m PEM -t rsa -b 4096 -C "[email protected]" to force ssh-keygen to export as PEM format.
Had the same problem, found the solution here.
basically use the PEM option when you create your key:
ssh-keygen -m PEM -t rsa
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With