您好我有一点问题,我开发了一个脚本sftp客户端,节点js连接到sftp服务器并获取一些文件,我测试它与我的本地服务器工作,但当我试图用它与生产服务器我收到了这个错误:
错误:握手失败:没有匹配的密钥交换算法
我已经使用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']
}
};
答案 0 :(得分:1)
您可以在服务器上编辑/ etc / ssh / sshd配置文件,以便允许密钥验证方法:)
答案 1 :(得分:1)
您是否尝试过将算法声明更改为...?
algorithms: {
serverHostKey: [ 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96' ],
}
答案 2 :(得分:1)
对于我自己,我将 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"
]
}
}
添加此算法后,我的机器上连接成功
答案 3 :(得分:0)
我的第一个建议是升级您连接的服务器上的ssh服务器,以便可以获得更安全的配置。这是最好/最安全的解决方案。
如果您无法在此服务器上进行更改并且您绝对需要连接,那么可以将kex
显式设置为您要支持的密钥交换方法列表(有效算法)名称可以在ssh2-streams
documentation中找到。例如:
algorithms: {
kex: [ ... ]
}
答案 4 :(得分:0)
我也遇到了同样的问题,并通过添加以下内容解决了该问题:
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"
]
}