@electerm/ssh2

中文文档
1.23.0发布于 2026/10/31CommonJS构建来源已验证近 30 天下载 3952

SSH2 client and server modules written in pure JavaScript for node.js

原始使用文档
文档目录9 节
  1. Installation
  2. Additional Features
  3. SM2 / SM3 / SM4 (Chinese National Crypto) Support
  4. SSH Certificate Login
  5. Enhanced Keepalive
  6. SFTP Non-UTF8 Encoding Support
  7. Other Improvements & Fixes
  8. electerm Related Projects
  9. License

@electerm/ssh2

English | 中文

A fork of ssh2 — SSH2 client and server modules written in pure JavaScript for Node.js.

This library is designed for and used by electerm, an open-sourced terminal/ssh/sftp/ftp/telnet/serialport/RDP/VNC/Spice client for Linux, Mac, Windows, and Android.

Installation

npm i @electerm/ssh2

Additional Features

Built on top of the original ssh2, this fork adds the following features:

SM2 / SM3 / SM4 (Chinese National Crypto) Support

Full support for Chinese national cryptographic standards (GM/T), with no native compilation required (pure JavaScript):

AlgorithmTypeDescription
sm2kep-sha3-sm3Key ExchangeSM2 ECDH key exchange with SM3 hash
ssh-sm2Host Key / SignatureSM2 signature with SM3 hash
sm4-ctr, sm4-cbcCipherSM4 block cipher
hmac-sm3, [email protected]MACHMAC with SM3 hash

See SM Guide for details.

SSH Certificate Login

Authenticate using SSH certificates via the new certificate connect option:

client.connect({
  host: '127.0.0.1',
  username: 'admin',
  privateKey: fs.readFileSync('/path/to/key'),
  certificate: fs.readFileSync('/path/to/cert'),  // SSH certificate
});

Enhanced Keepalive

Both TCP-level (SO_KEEPALIVE) and SSH protocol-level keepalives to reliably detect and clean up dead connections.

SFTP Non-UTF8 Encoding Support

Added an encode option to handle SFTP file names and shell output in non-UTF8 encodings (e.g. GBK):

client.connect({
  // ...
  encode: 'gbk',
});

Other Improvements & Fixes

  • Support for EXT_INFO messages
  • Fix zlib errors crashing the session
  • Fix large text in SFTP headers breaking the connection
  • Force RSA key support even when the server does not agree
  • No native build required — replaces optionalDependencies with regular dependencies
ProjectDescription
electermDesktop app (Linux, Mac, Windows)
electerm-webBrowser-based version (including mobile)
electerm-web-dockerDocker image for electerm-web
electerm onlinePublic free online app
electerm demoOnline demo
electerm-localesMulti-language support
electerm AIFree AI for electerm users
electerm-androidAndroid app

License

MIT

版本与发布记录

@electerm/ssh2 共发布 39 个版本,首次发布于 2018/12/18;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.23.0latest2026/10/3113 天前
1.22.22026/10/2717 天前
1.22.12026/09/151 个月前
1.22.02026/07/233 个月前
1.21.02026/07/233 个月前
1.20.12026/06/304 个月前

关于 @electerm/ssh2 的常见问题

@electerm/ssh2 是什么?

SSH2 client and server modules written in pure JavaScript for node.js

如何安装 @electerm/ssh2?

在项目目录运行 npm install @electerm/ssh2,或使用 pnpm add / yarn add / bun add。

@electerm/ssh2 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/electerm__ssh2 是否存在。

@electerm/ssh2 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@electerm/ssh2 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10.16.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@electerm/ssh2 可以商用吗?

@electerm/ssh2 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@electerm/ssh2 的下载量有多少?

根据 npm 官方下载统计,@electerm/ssh2 在 2026/10/14 – 2026/11/12 这 30 天内被下载 3,952 次,日均约 132 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@electerm/ssh2 还在维护吗?

最新版本 1.23.0 发布于 2026/10/31(13 天前);至今共发布 39 个版本,其中过去 12 个月发布了 14 个;首次发布于 2018/12/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。