连接到 sftp.webtrends.com 时没有匹配的主机密钥

No matching host key when connecting to sftp.webtrends.com

我正在尝试使用 Firebase Cloud Functions 将文件发送到 webtrends ftp 服务器,但我遇到了无法解决的问题。因为我使用 Firebase Cloud Functions,所以我的函数是来自 nodejs 服务器的 运行。我正在使用这个 npm 包:https://www.npmjs.com/package/ssh2-sftp-client.

在线阅读并解释调试日志后,我了解到问题在于服务器使用了已弃用的加密算法 (ssh-dss)。我在这里读到 https://www.openssh.com/legacy.html ssh-dss 是遗留的,因此不受 ssh2 支持。

我找到的大多数其他解决方案都告诉我配置 ssh 配置,但在这种情况下我无权访问远程并且无法配置它。

这是我用来连接的代码:

const Client = require('ssh2-sftp-client');
const sftp = new Client();
sftp.connect({
  host: 'sftp.webtrends.com',
  port: '****', // omitted
  username: '****', // omitted
  password: '****', // omitted
  algorithms: {
    serverHostKeys: ['ssh-dss'],
  },
});

这是调试日志:

DEBUG: Local ident: 'SSH-2.0-ssh2js0.1.20'
DEBUG: Client: Trying sftp.webtrends.com on port **** ...
DEBUG: Client: Connected
DEBUG: Parser: IN_INIT
DEBUG: Parser: IN_GREETING
DEBUG: Parser: IN_HEADER
DEBUG: Remote ident: 'SSH-2.0-1.82_sshlib GlobalSCAPE'
DEBUG: Parser: IN_PACKET
DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
DEBUG: Parser: IN_PACKETDATA
DEBUG: Parser: IN_PACKETDATAAFTER, packet: KEXINIT
DEBUG: Comparing KEXINITs ...
DEBUG: (remote) KEX algorithms: diffie-hellman-group14-sha1,diffie-hellman-
group-exchange-sha1,diffie-hellman-group1-sha1
DEBUG: (local) KEX algorithms: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-
sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
DEBUG: (local) Host key formats: ssh-rsa,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
DEBUG: Outgoing: Writing KEXINIT
DEBUG: Parser: pktLen:484,padLen:11,remainLen:480
DEBUG: Outgoing: Writing DISCONNECT (KEY_EXCHANGE_FAILED)
DEBUG: KEX algorithm: diffie-hellman-group14-sha1
DEBUG: (remote) Host key formats: ssh-dss
DEBUG: No matching host key format

因此,如果您无法配置服务器,并且 ssh2-sftp-client 表示不支持 ssh-dss,您唯一的选择是不使用 ssh2-sftp-client,而是使用另一个支持 ssh-dss.

的包

快速 Google 搜索 nodejs ftp client "ssh-dss",应该不难找到支持 ssh-dss 的,例如 yocto-sftp

您的配置选项中有错字。按照 in the docs 所述使用这些设置,它可能有效:

algorithms: {
  serverHostKey: ['ssh-dss'], // serverHostKey, without the 's'
},