ssh2节点js sftp协议错误握手失败
ssh2 node js sftp protocol Error Handshake failed
你好,我有一个小问题,我用节点 js 开发了一个脚本 sftp 客户端,它连接到一个 sftp 服务器并抓取一些文件,我用我的本地服务器测试了它的工作,但是当我尝试使用它时生产服务器我收到此错误:
Error: Handshake failed: no matching key exchange algorithm
我已经使用 ssh-keygen
生成了 rsa 密钥
这是脚本的相关部分:
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']
}
};
您可以在您的服务器上编辑您的 /etc/ssh/sshd 配置文件,以允许密钥身份验证方法:)
我的第一个建议是升级您要连接的服务器上的 ssh 服务器,以便获得更安全的配置。这是 best/most 安全解决方案。
如果您无法在此服务器上进行更改并且您绝对需要连接,那么您可以明确地将kex
设置为您想要的密钥交换方法列表支持(有效的算法名称可以在 ssh2-streams
documentation 中找到)。例如:
algorithms: {
kex: [ ... ]
}
您是否尝试过将您的算法声明更改为...?
algorithms: {
serverHostKey: [ 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96' ],
}
我也遇到了同样的问题,通过添加以下内容解决了这个问题:
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"
]
}
对于我自己,我将 debug: console.log
添加到我的配置对象中。此输出有关连接尝试的更多信息。
{
"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
基于这个错误,我更新了我的配置算法:
{
"port": 22,
"host": "test.test.com",
"user": "test",
"password": "******",
"algorithms": {
"kex": [
"diffie-hellman-group14-sha1","diffie-hellman-group-exchange-sha1"
]
}
}
添加此算法后,在我的机器上连接成功
你好,我有一个小问题,我用节点 js 开发了一个脚本 sftp 客户端,它连接到一个 sftp 服务器并抓取一些文件,我用我的本地服务器测试了它的工作,但是当我尝试使用它时生产服务器我收到此错误:
Error: Handshake failed: no matching key exchange algorithm
我已经使用 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']
}
};
您可以在您的服务器上编辑您的 /etc/ssh/sshd 配置文件,以允许密钥身份验证方法:)
我的第一个建议是升级您要连接的服务器上的 ssh 服务器,以便获得更安全的配置。这是 best/most 安全解决方案。
如果您无法在此服务器上进行更改并且您绝对需要连接,那么您可以明确地将kex
设置为您想要的密钥交换方法列表支持(有效的算法名称可以在 ssh2-streams
documentation 中找到)。例如:
algorithms: {
kex: [ ... ]
}
您是否尝试过将您的算法声明更改为...?
algorithms: {
serverHostKey: [ 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96' ],
}
我也遇到了同样的问题,通过添加以下内容解决了这个问题:
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"
]
}
对于我自己,我将 debug: console.log
添加到我的配置对象中。此输出有关连接尝试的更多信息。
{
"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
基于这个错误,我更新了我的配置算法:
{
"port": 22,
"host": "test.test.com",
"user": "test",
"password": "******",
"algorithms": {
"kex": [
"diffie-hellman-group14-sha1","diffie-hellman-group-exchange-sha1"
]
}
}
添加此算法后,在我的机器上连接成功