5

您好,我有一个小问题,我使用节点 js 开发了一个脚本 sftp 客户端,它连接到 sftp 服务器并获取一些文件,我用我的本地服务器对其工作进行了测试,但是当我尝试将它与生产服务器一起使用时,我收到了这个错误 :

错误:握手失败:没有匹配的密钥交换算法

我已经使用生成了 rsa 密钥ssh-keygen

这是脚本的相关部分:

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']
    }

};
4

5 回答 5

4

我也遇到了同样的问题并通过添加以下内容解决了它:

algorithms: {
        kex: [
          "diffie-hellman-group1-sha1",
          "ecdh-sha2-nistp256",
          "ecdh-sha2-nistp384",
          "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"
        ]
    }
于 2019-09-19T16:32:31.107 回答
3

对于我自己,我添加debug: console.log到我的配置对象中。此输出有关连接尝试的更多信息。

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

握手:(远程)KEX 方法:diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1

握手:没有匹配的密钥交换算法

基于这个错误,我更新了我的配置算法:

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

添加此算法后,我的机器上的连接成功

于 2021-07-22T20:27:58.157 回答
2

我的第一个建议是升级您要连接的服务器上的 ssh 服务器,以便进行更安全的配置。这是最好/最安全的解决方案。

如果您无法在此服务器上进行更改并且您绝对需要连接,那么您可以将显式设置为kex您想要支持的密钥交换方法列表(可以在ssh2-streams文档中找到有效的算法名称)。例如:

algorithms: {
  kex: [ ... ]
}
于 2017-01-18T18:25:47.357 回答
2

您可以在您的服务器上编辑您的 /etc/ssh/sshd 配置文件,以允许密钥身份验证方法:)

于 2017-01-18T16:49:10.520 回答
2

您是否尝试过将您的算法声明更改为...?

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

于 2018-10-26T11:17:01.503 回答