You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下NodeJS用OpenSSH无需Pageant的代理选型及包适配问题

解决方案:Windows下node-ssh/ssh2直接对接OpenSSH代理

核心配置修改

Windows系统的微软OpenSSH代理默认使用的管道路径是\\.\pipe\openssh-ssh-agent,你可以直接把agent字段指向这个路径,无需依赖Pageant或桥接工具。

node-ssh 配置示例

修改你的配置为:

this.server.ftpConfig = {
  // 其他原有配置...
  agent: process.platform === 'win32' ? '\\\\.\\pipe\\openssh-ssh-agent' : process.env.SSH_AUTH_SOCK,
  agentForward: true, // Windows下也可按需启用代理转发
};

注意:Windows路径中的反斜杠需要转义,因此写成双反斜杠形式。

ssh2 包适配

ssh2作为node-ssh的底层依赖,完全支持相同的配置逻辑——只需将agent参数指定为OpenSSH的管道路径即可,示例:

const Client = require('ssh2').Client;

const conn = new Client();
conn.connect({
  // 其他连接配置(主机、端口、用户名等)...
  agent: process.platform === 'win32' ? '\\\\.\\pipe\\openssh-ssh-agent' : process.env.SSH_AUTH_SOCK,
  agentForward: true
});

验证前提

确保你的Windows系统满足以下条件:

  • 已安装微软官方OpenSSH客户端(Windows 10 1809+或Windows 11默认自带,旧版本可通过「设置-应用-可选功能」安装)
  • OpenSSH代理服务已启动:
    1. 打开PowerShell,执行 Get-Service ssh-agent 确认服务状态
    2. 未启动则执行 Start-Service ssh-agent,并设置开机自启 Set-Service -Name ssh-agent -StartupType 'Automatic'
  • 已将SSH密钥添加到代理:执行 ssh-add C:\path\to\your\private-key

内容的提问来源于stack exchange,提问作者Sander_P

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 09:08:14