是否可以更新 Windows 10 中的内置 OpenSSH 客户端?

vic*_*vic 17 ssh powershell openssh windows-10

我遇到了内置 OpenSSH 客户端的某些问题,根据Win32-OpenSSH Github页面,这些问题似乎在较新版本中已解决。最新版本是 v7.9,而预装的客户端版本是 7.6p1。

PS C:\> ssh -V
OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4
Run Code Online (Sandbox Code Playgroud)

我知道可以在“应用程序和功能”设置页面中将 OpenSSH 作为可选功能安装,也可以使用 Powershell。在我的情况下,这似乎是徒劳的,因为显然已经安装了客户端。

PS C:\>  Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'

Name  : OpenSSH.Client~~~~0.0.1.0
State : Installed

Name  : OpenSSH.Server~~~~0.0.1.0
State : NotPresent
Run Code Online (Sandbox Code Playgroud)

不幸的是,似乎不可能以这种方式更新客户端,而且 Github 页面似乎没有发布二进制文件。这是否意味着如果我想使用更新的版本,我必须自己制作二进制文件,它们甚至可以作为未签名的替代品或其他任何东西吗?也许有更简单的方法?

ᄂ ᄀ*_*ᄂ ᄀ 14

  1. 删除 OpenSSH 的默认版本:
Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Run Code Online (Sandbox Code Playgroud)
  1. 安装最新版本:
  1. 将其添加到路径:
[Environment]::SetEnvironmentVariable("Path", 
$env:Path + ';' + ${Env:ProgramFiles} + '\OpenSSH', 
[System.EnvironmentVariableTarget]::Machine)
Run Code Online (Sandbox Code Playgroud)


Red*_*dio 12

页面提供了使用 Powershell 安装最新软件包的步骤。

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url = 'https://github.com/PowerShell/Win32-OpenSSH/releases/latest/'
$request = [System.Net.WebRequest]::Create($url)
$request.AllowAutoRedirect=$false
$response=$request.GetResponse()
$([String]$response.GetResponseHeader("Location")).Replace('tag','download') + '/OpenSSH-Win64.zip'  
$([String]$response.GetResponseHeader("Location")).Replace('tag','download') + '/OpenSSH-Win32.zip'
Run Code Online (Sandbox Code Playgroud)

如果你使用的巧克力,然后键入以下命令提示符如图所示在这里

choco upgrade openssh
Run Code Online (Sandbox Code Playgroud)

  • 您可能希望使用此 [页面](https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH) 上的说明来安装更新。但是,我会在虚拟机中执行测试,以验证实际发生的情况。除非您特别担心存在漏洞,否则您可能不想尝试手动更新安装,而是删除内置版本并使用上述安装说明。 (4认同)
  • 两者都没有做太多事情,至少不提供任何输出,然后(即使在打开新的 shell 后) `ssh -V` 只给我相同的输出:`OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5` (3认同)

小智 5

二进制文件现在在GitHub 上。下载最新版本并在 C:\Windows\System32 中更新它们。


JPv*_*iel 5

覆盖文件的答案有效:

下载最新版本并在 C:\Windows\System32 中更新它们。

然而,这说起来容易做起来难,因为 Windows 如何限制在 System32 中修改/写入文件的权限。以管理员身份运行 PowerShell 不足以修改文件。我必须更改所有权并添加完全控制权限才能完成如下操作:

# Download upstream bins
$url = 'https://github.com/PowerShell/Win32-OpenSSH/releases/latest/'
$request = [System.Net.WebRequest]::Create($url)
$request.AllowAutoRedirect=$false
$response=$request.GetResponse()
$source = $([String]$response.GetResponseHeader("Location")).Replace('tag','download') + '/OpenSSH-Win64.zip'
(New-Object System.Net.WebClient).DownloadFile($source, 'OpenSSH-Win64.zip')



# Overwrite windows installed bins
$openSshBins = (Get-ChildItem 'C:\WINDOWS\System32\OpenSSH\').Name
Expand-Archive -Path .\OpenSSH-Win64.zip -DestinationPath .
takeown.exe /a /r /f C:\Windows\System32\OpenSSH\
icacls.exe 'C:\Windows\System32\OpenSSH' /grant 'BUILTIN\Administrators:(OI)(CI)F'
icacls.exe 'C:\Windows\System32\OpenSSH' /grant 'BUILTIN\Administrators:F' /t
Stop-Service ssh-agent
$openSshBins | %{ Copy-Item -Path .\OpenSSH-Win64\$_ -Destination C:\Windows\System32\OpenSSH\ }
Start-Service ssh-agent
Run Code Online (Sandbox Code Playgroud)

请注意,要自动下载,您需要允许重定向。