Skip to content

Releases: badseal/ssh-skill

v3.3.0 - Windows 原生 SSH 适配 & Passphrase 密钥支持

24 Mar 08:37

Choose a tag to compare

🔑 Windows 原生 SSH 适配与 Passphrase 密钥支持

本次更新解决了 SSH Skill 在 Windows 环境下无法使用 passphrase 保护的密钥进行连接的问题。通过将 SSH 调用链从 Git 自带的 SSH 切换为 Windows 原生 OpenSSH,实现了与 Windows SSH Agent 服务的完整集成。

✨ 新功能

  • 🔑 Passphrase 密钥完整支持 — 通过 Windows SSH Agent 集成,passphrase 保护的密钥可以无感使用,无需每次交互输入密码
  • 🪟 Windows 原生 SSH 适配 — 自动定位 %SystemRoot%\System32\OpenSSH\ssh.exe,解决 Git SSH 与 Windows 原生 SSH 的 PATH 优先级冲突
  • 🔌 SSH 隧道管理 — 新增本地端口转发功能(ssh_tunnel.py),支持:
    • 守护进程模式运行
    • 自动重连和心跳检测(60s 间隔)
    • 空闲 30 分钟自动退出
    • 支持跳板机(ProxyJump)
    • 自动分配本地端口(10000-20000)
    • 完整的 start/list/status/stop/stop-all 命令
  • 🛡️ Windows SSH Agent 工具windows_ssh_agent.py) — 一键检测、启动和配置 Windows OpenSSH Authentication Agent 服务

🐛 Bug 修复

  • 补全 check_windows_ssh_availability() 缺失函数(之前被调用但从未实现)
  • 修复 execute_native_ssh() 中 SSH 命令路径被 Git SSH 抢占的问题
  • 修复 check_ssh_agent() 中 ssh-add 无法连接 Windows Agent 的问题

🔧 问题根因

在安装了 Git for Windows 的系统上,存在两套 SSH:

优先级 1: C:\Program Files\Git\usr\bin\ssh.exe   ← Git SSH(无法连接 Windows SSH Agent)
优先级 2: C:\WINDOWS\System32\OpenSSH\ssh.exe    ← Windows 原生 SSH(可以)

即使通过 PowerShell 调用 ssh,实际执行的也是 Git 版本,导致所有 passphrase 密钥连接失败。

解决方案:通过 %SystemRoot% 环境变量动态定位原生 OpenSSH 的绝对路径,在 PowerShell 中使用 & "绝对路径" 语法确保调用正确的 SSH。

📊 测试结果

测试场景 v3.2 v3.3
普通密钥直连
普通密钥 + 堡垒机
Passphrase 密钥 ❌ 崩溃 ✅ 正常
SSH Agent 密钥检测 ❌ 无法连接 ✅ 正确识别

全量测试 23 台服务器:成功率 74%(17/23),平均耗时 1.39s,失败均为环境/配置原因。

📁 变更文件

  • scripts/lib/native_ssh_fallback.py — 新增路径定位、可用性检查,修复 SSH/ssh-add 调用路径
  • scripts/lib/windows_ssh_agent.py — 新增 Windows SSH Agent 配置工具
  • scripts/ssh_tunnel.py — 新增 SSH 隧道管理
  • scripts/ssh_execute.py — 更新智能客户端选择逻辑
  • scripts/lib/paramiko_client.py — 连接参数优化
  • SKILL.md — 添加隧道命令和 passphrase 文档
  • README.md / README_EN.md — 添加更新说明

📋 使用前置条件(Windows)

# 1. 启动 Windows SSH Agent(管理员 PowerShell)
Set-Service -Name ssh-agent -StartupType Automatic
Start-Service ssh-agent

# 2. 添加 passphrase 密钥到 Agent
ssh-add C:\Users\你的用户名\.ssh\你的密钥文件

# 3. 之后 SSH Skill 会自动处理一切 ✨

Full Changelog: v3.2...v3.3.0