I've tried using ssh2 and node-ssh libraries to connect,
but I always get "Cannot parse privateKey: Unsupported key format"
I'm getting the key from AWS secret manager in this format -----BEGIN PRIVATE KEY----- ....---END PRIVATE KEY-----
, I tried adding 'BEGIN RSA' or 'BEGIN OPENSSH' (also added them at the end of the file) still getting the same error, I tried using ssh-keygen -m PEM -t rsa
and navigate to this file and still I get this error, I managed to workaround with exec a child process but it's not ideal, I'm trying to avoid saving the key as file and use directly the string I'm getting from the secret manager
ssh.connect({
host: 'my-server.example.com',
port: 22,
username: 'my-username',
privateKey: // string from secret manager in the format mentioned above
});
you can refer below updates using the
node-ssh
npm package more can be seen here https://www.npmjs.com/package/node-ssh/v/13.1.0