3

I have searched stackoverflow and google extensivly and not found a solution yet.

Using Typescript, node v16.18.0 and ssh2-sftp-client, the code below can successfully connects to my sftp server (hosted on IIS) which requires a username, password and a private key.

let sftp = new Client(); // sftp.tryKeyboard = true; let conn = await sftp .connect({ protocal: 'sftp', host: '##.##.##.##', port: 22, username: 'someUserName', remotePath: 'somePaht', password: 'somePassword', privateKey: key, // tryKeyboard: true, }) .then(async() => { // return; console.log('You connected!'); }) .catch((err: any) => { console.log(err, 'catch error'); }); 

However, using the exact same code but passing in connection parameters for a different sftp server (hosted on Linux) that requires a username and privatekey, but not a password fails to connect.

let sftp = new Client(); // sftp.tryKeyboard = true; let conn = await sftp .connect({ protocal: 'sftp', host: '##.##.##.##', port: 22, username: 'gp', remotePath: 'gp', //password: 'NA', privateKey: key, // tryKeyboard: true, }) .then(async() => { // return; console.log('You connected!'); }) .catch((err: any) => { console.log(err, 'catch error'); }); 

and this is the error I get using the above code:

Error: connect: getConnection: All configured authentication methods failed at SftpClient.fmtError (D:\app\node_modules\ssh2-sftp-client\src\index.js:111:22) at SftpClient.connect (D:\app\node_modules\ssh2-sftp-client\src\index.js:249:37) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async getSftpConnection (D:\app\index.ts:67:12) { code: 'ERR_GENERIC_CLIENT', custom: true } catch error

As a test I used the exact same values to connect using the FileZilla ftp client and it connects with no problem. I don’t have admin access to the Linux server so I can’t get additional information about its configuration, but I can confirm that these connection parameter values work in FileZilla. Obviously FileZilla is doing something I am not.

This is the basic configuration in FileZilla:

enter image description here

enter image description here

and the folder it connected to:

enter image description here

How can I troubleshoot this? How can I get additional information about what’s causing the connection to fail?

Thank you.

1 Answer 1

3

It turns out that the type of key I was using was a rsa. IIS is much more forgiving then Linux. To make this work on the Linux sftp I had to add these 2 lines in the config file

hostkeyalgorithms=ssh-rsa,[email protected] pubkeyacceptedalgorithms=+ssh-rsa,[email protected] 

the config file is located at:

/etc/ssh/sshd_config 

Click here to see the config file

However, in this screenshot you can see that the 2 lines are commented out. Thats because after I got this to work, I commented them and tried using a key in the ED25519 format which did work.

Summary, I should have used a ED25519 type of key so I would not have needed to mess with the Linux server. But if I want to the rsa key, then add the 2 lines above to the config file.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.