相关文章推荐
爱笑的蜡烛  ·  DeviceInformation.Crea ...·  2 年前    · 
博学的瀑布  ·  pentaho spoon - PDI 7 ...·  2 年前    · 
冷冷的盒饭  ·  js数组转对象 - 掘金·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Hello i have a little problem, i developped a script sftp client with node js that connect to an sftp server and grab some files, i tested it with my local server its working, but when i tried to use it with production server i received this error :

Error: Handshake failed: no matching key exchange algorithm

i already generated the rsa key using ssh-keygen

here is the relevant part of the script :

var Client = require('ssh2').Client;
var fs = require('fs');
var path = require('path');
var args = process.argv.slice(2);
var connSettings = {
    host: args[0] || '127.0.0.1',
    port: args[1] || 22,
    username: args[2] || 'karim',
    password: args[3] || 'karimos',
    algorithms: {
        hmac: ['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96']
          "ecdh-sha2-nistp521",
          "diffie-hellman-group-exchange-sha256",
          "diffie-hellman-group14-sha1"
        cipher: [
          "3des-cbc",
          "aes128-ctr",
          "aes192-ctr",
          "aes256-ctr",
          "aes128-gcm",
          "aes128-gcm@openssh.com",
          "aes256-gcm",
          "aes256-gcm@openssh.com"
        serverHostKey: [
          "ssh-rsa",
          "ecdsa-sha2-nistp256",
          "ecdsa-sha2-nistp384",
          "ecdsa-sha2-nistp521"
        hmac: [
          "hmac-sha2-256",
          "hmac-sha2-512",
          "hmac-sha1"

For myself, I added debug: console.log to my config object. This output more about the connection attempt.

"port": 22, "host": "test.test.com", "user": "test", "password": "******", "debug": console.log

Handshake: (remote) KEX method: diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1

Handshake: No matching key exchange algorithm

Based on this error I updated my config's algorithm:

"port": 22, "host": "test.test.com", "user": "test", "password": "******", "algorithms": { "kex": [ "diffie-hellman-group14-sha1","diffie-hellman-group-exchange-sha1"

After adding this algorithm the connection was successful on my machine

can you give me some reference, but i have used filezilla to connect to the server and its worked, also i tried without the algorithms: { hmac: ['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96'] } and its didn't worked – KarimS Jan 18, 2017 at 17:21

My first suggestion would be to upgrade the ssh server on the server you're connecting to so that a more secure configuration can be had. This is the best/most secure solution.

If you cannot make changes on this server and you absolutely need to connect, then you can explicitly set the kex to a list of key exchange methods you want to support (valid algorithm names can be found in the ssh2-streams documentation). For example:

algorithms: {
  kex: [ ... ]

algorithms: { serverHostKey: [ 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96' ],

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.