不同的windows版本,对应的安装方式不同。
为了确保OpenSSH可用,请运行
shell>Get-WindowsCapability-Online|Where-ObjectName-like'OpenSSH*'如果两者均尚未安装,则此操作应返回以下输出:
Name:OpenSSH.Client~~~~0.0.1.0State:NotPresentName:OpenSSH.Server~~~~0.0.1.0State:NotPresent然后,根据需要安装服务器或客户端组件:
#InstalltheOpenSSHClientAdd-WindowsCapability-Online-NameOpenSSH.Client~~~~0.0.1.0#InstalltheOpenSSHServerAdd-WindowsCapability-Online-NameOpenSSH.Server~~~~0.0.1.0这两者应该都会返回以下输出:
Path:Online:TrueRestartNeeded:False1.2.2启动并配置OpenSSH服务器#StartthesshdserviceStart-Servicesshd#OPTIONALbutrecommended:Set-Service-Namesshd-StartupType'Automatic'#ConfirmtheFirewallruleisconfigured.Itshouldbecreatedautomaticallybysetup.Runthefollowingtoverifyif(!(Get-NetFirewallRule-Name"OpenSSH-Server-In-TCP"-ErrorActionSilentlyContinue|Select-ObjectName,Enabled)){Write-Output"FirewallRule'OpenSSH-Server-In-TCP'doesnotexist,creatingit..."New-NetFirewallRule-Name'OpenSSH-Server-In-TCP'-DisplayName'OpenSSHServer(sshd)'-EnabledTrue-DirectionInbound-ProtocolTCP-ActionAllow-LocalPort22}else{Write-Output"Firewallrule'OpenSSH-Server-In-TCP'hasbeencreatedandexists."}1.3windows旧版安装1.3.1下载OpenSSHServer您可以从GitHub上下载适用于Windows的OpenSSH二进制文件。
shell>cd"C:\ProgramFiles\OpenSSH"1.3.3安装OpenSSH服务shell>.\install-sshd.ps1shell>.\install-shield.ps11.3.4配置并启动OpenSSH
安装完成后,启动sshd服务:
netstartsshd确保OpenSSH在启动时自动启动:
Set-Service-Namesshd-StartupType'Automatic'打开防火墙以允许SSH连接:
New-NetFirewallRule-Namesshd-DisplayName'OpenSSHServer(sshd)'-EnabledTrue-DirectionInbound-ProtocolTCP-ActionAllow-LocalPort22验证OpenSSH安装
Get-Service-Namesshd启动和停止服务:Start-ServicesshdStop-Servicesshd查看日志:您可以查看C:\ProgramData\ssh\logs文件夹中的日志文件,以调试任何可能出现的问题。
shell>sshusername@servername1.5windows卸载OpenSSH#UninstalltheOpenSSHClientRemove-WindowsCapability-Online-NameOpenSSH.Client~~~~0.0.1.0#UninstalltheOpenSSHServerRemove-WindowsCapability-Online-NameOpenSSH.Server~~~~0.0.1.0
Anythinginherewillbereplacedonbrowsersthatsupportthecanvaselement