Windows 10下PowerShell无法安装并启动OpenSSH Server求助
解决Windows 10 21H2中PowerShell安装OpenSSH.Server始终显示NotPresent的问题
步骤1:确认Windows Update服务正常运行
- 检查Windows Update相关核心服务的状态:
Get-Service wuauserv, cryptSvc, bits, msiserver - 如果上述服务未处于运行状态,执行以下命令启动并配置开机自启:
Start-Service wuauserv, cryptSvc, bits, msiserver Set-Service wuauserv -StartupType Automatic Set-Service cryptSvc -StartupType Automatic Set-Service bits -StartupType Automatic Set-Service msiserver -StartupType Manual
步骤2:重置Windows Update组件
若Windows Update服务正常但仍无法获取安装包,重置组件修复潜在损坏:
- 停止相关服务:
Stop-Service wuauserv, cryptSvc, bits, msiserver -Force - 重命名更新缓存文件夹:
Rename-Item C:\Windows\SoftwareDistribution SoftwareDistribution.old -Force Rename-Item C:\Windows\System32\catroot2 catroot2.old -Force - 重新注册Windows Update相关DLL文件:
$dlls = @( 'atl.dll', 'urlmon.dll', 'mshtml.dll', 'shdocvw.dll', 'browseui.dll', 'jscript.dll', 'vbscript.dll', 'scrrun.dll', 'msxml.dll', 'msxml3.dll', 'msxml6.dll', 'actxprxy.dll', 'softpub.dll', 'wintrust.dll', 'dssenh.dll', 'rsaenh.dll', 'gpkcsp.dll', 'sccbase.dll', 'slbcsp.dll', 'cryptdlg.dll', 'oleaut32.dll', 'ole32.dll', 'shell32.dll', 'initpki.dll', 'wuapi.dll', 'wuaueng.dll', 'wuaueng1.dll', 'wucltui.dll', 'wups.dll', 'wups2.dll', 'wuweb.dll', 'qmgr.dll', 'qmgrprxy.dll', 'wucltux.dll', 'muweb.dll', 'wuwebv.dll' ) foreach ($dll in $dlls) { regsvr32.exe /s $dll } - 重置Winsock:
netsh winsock reset - 重启相关服务:
Start-Service wuauserv, cryptSvc, bits, msiserver
步骤3:使用DISM命令指定安装源尝试安装
如果前两步无效,用DISM直接指定安装源强制安装:
方法A:使用Windows Update在线源
- 执行以下命令:
DISM /Online /Add-Capability /CapabilityName:OpenSSH.Server~~~0.0.1.0 /Source:WindowsUpdate
方法B:使用本地Windows 10镜像源(需提前准备对应版本ISO)
- 挂载ISO镜像(替换为你的ISO路径):
Mount-DiskImage -ImagePath "C:\Downloads\Windows10_21H2.iso" - 查看挂载盘符(通常为新增的光驱盘符,比如D:):
Get-Volume | Where-Object {$_.FileSystemLabel -eq "Windows 10"} - 执行安装命令(替换D:为实际挂载盘符):
DISM /Online /Add-Capability /CapabilityName:OpenSSH.Server~~~0.0.1.0 /Source:D:\sources\sxs - 安装完成后卸载镜像:
Dismount-DiskImage -ImagePath "C:\Downloads\Windows10_21H2.iso"
步骤4:验证安装并启动服务
安装完成后,确认状态并配置服务:
- 检查OpenSSH.Server的安装状态:
Get-WindowsCapability -Online | Where-Object Name -like '*OpenSSH.Server*' - 启动sshd和ssh-agent服务,并设置开机自启:
Start-Service sshd, ssh-agent Set-Service sshd -StartupType Automatic Set-Service ssh-agent -StartupType Automatic - 验证服务运行状态:
Get-Service sshd, ssh-agent
内容的提问来源于stack exchange,提问作者frustratedscreaming
相关产品推荐
相关产品推荐

