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

PowerShell 7无法使用SSH的问题排查与解决求助

解决PowerShell 7中无法识别ssh命令的问题

问题重现

在PowerShell 7中执行ssh命令时出现如下错误:

ssh: The term 'ssh' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

该命令在CMD和Windows PowerShell中可正常运行,但无法直接切换到C:\Windows\System32\OpenSSH目录。

解决方案

1. 检查PowerShell 7的进程位数

这是最常见的原因:Windows的OpenSSH默认安装在C:\Windows\System32\OpenSSH,但32位版本的PowerShell 7会被系统重定向,无法直接访问System32目录(实际访问的是C:\Windows\SysWOW64)。

  • 在PowerShell 7中执行:
    [Environment]::Is64BitProcess
    
  • 如果返回False,说明你使用的是32位PowerShell 7,卸载并重新安装64位版本即可解决问题。

2. 绕过目录重定向访问OpenSSH(临时方案)

如果暂时无法切换到64位PowerShell,可通过Sysnative路径绕过重定向:

  • 执行以下命令进入OpenSSH目录:
    cd C:\Windows\Sysnative\OpenSSH
    
  • 直接运行完整路径的ssh命令测试:
    C:\Windows\Sysnative\OpenSSH\ssh.exe
    

3. 刷新环境变量

如果已经确认是64位PowerShell 7,但仍无法识别ssh,可能是环境变量未生效:

  • 执行以下命令强制刷新系统Path到当前会话:
    $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
    
  • 之后再尝试执行ssh命令。

4. 重新安装OpenSSH客户端

确保OpenSSH客户端安装正确:

  1. 打开Windows设置 → 应用 → 可选功能
  2. 找到「OpenSSH 客户端」,点击卸载
  3. 卸载完成后,点击「添加功能」,重新搜索并安装「OpenSSH 客户端」
  4. 安装完成后重启PowerShell 7测试

内容的提问来源于stack exchange,提问作者Adnan Bin Zahir

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 07:51:09