steelbrain / node-ssh

SSH2 with Promises
MIT License
943 stars 94 forks source link

privateKey: Buffer.from('...') #446

Open YanDevDe opened 2 years ago

YanDevDe commented 2 years ago

README.md shows privateKey: Buffer.from('...'), but I assume the privateKey expects only string, or not? Would fix this typo to avoid confusion as setting Buffer in privateKey actually won't work.

eyal-solomon1 commented 2 years ago

@YanDevDe facing the same issue .. what did work for you ?

YanDevDe commented 2 years ago

Convert the Buffer to string:

privateKey: buffer.toString(“utf8”)

Make sure that the key is in PEM format (if not, you may need to convert it)

ecker00 commented 1 year ago

Would think that reading the file as UTF-8 would work, but I get:

const privateKey = await fs.readFile(env.SSH_privateKey, 'utf-8');
// Error: ENOENT: no such file or directory, stat '-----BEGIN OPENSSH PRIVATE KEY----- …

I also get errors when I try to use the privateKeyPath approach:

const privateKeyPath = '/myPathTo/id_ed25519';
// TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined

So not figured out how to get this to work, and had to downgrade to 12.05 for now.

EDIT: Turns out my first approach worked, also what steelbrain suggested bellow, but I had some error checks in my own client that was the issue.

steelbrain commented 1 year ago

@ecker00 I think you're trying to read the private key (which is already the key itself, not a path) as a path from the filesystem.

In your case, you may be able to get away with just replacing with the following code:

const privateKey = Buffer.from(env.SSH_privateKey, 'utf-8')