Unsupported key format when parsing private key in node

163 Views Asked by At

I'm trying to connect to a remote sftp server using ssh2-sftp-client package with a private key instead of a password. I have previously used a sftp client, loaded that file and connected successfully.. but it seems that the Putty private key is unsupported by the ssh2-sftp-client.

await sftp.connect({ host, port, username, privateKey: fs.readFileSync('/path/to/PrivateKey.ppk') })

PrivateKey.ppk

PuTTY-User-Key-File-3: ssh-rsa
Encryption: none
Comment: rsa-key-20230905
Public-Lines: 6
AAAAB3NzaC1yc2EAAAADAQABAAABAQCDe1c2LLpP6PYi5t9/Zc9WimRbxGnTfwCn
...
xOWIYcAFGofHXaRFZw749CdvL+AE6hI1+mh1dwoe20TVrZPDbBD7
Private-Lines: 14
AAABACkq7VuhFZT/tFGpSEFzdz/5hQLWtOvr0CClivB/GuXE+20BBenzJLSJC4QP
...
6NPp7Y7d9WXOS8ow2YRewfG5dYWnTUfFgdc33LJNmHh35w==
Private-MAC: 7a3dd935dd3edd18f4f5b5c42fdbcb2f727d8635db582a6adfedaafe6d6c3af9

Any idea why and how I can make it work?

1

There are 1 best solutions below

0
shAkur On

LE: private key need to be formatted from a putty format to an open SSH one. I followed this tutorial and made it work