在 Windows Server 2019 安装 Open-SSH 无错版笔记 (补充)

之前写过一篇
在 Windows Server 2019 安装 Open-SSH 无错版笔记

但是有些机器因为网路环境不允许
下指令安装还是没那么方便

透过指令安装Open-SSH

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

会得到错误讯息

    Add-WindowsCapability : The service cannot be started, either because it is disabledor because it has no enabled devices associated with it.At line:1 char:1+ Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [Add-WindowsCapability], COMException    + FullyQualifiedErrorId : Microsoft.Dism.Commands.AddWindowsCapabilityCommand

可以透过预先下载的方式
https://github.com/PowerShell/Win32-OpenSSH/releases

把 OpenSSH-Win64.zip 解压后的文件夹複製到 C:\OpenSSH

确认所有用户都必须可以存取 libcrypto.dll 文件:

&icacls C:\OpenSSH\libcrypto.dll /grant Everyone:RX

用管理员模式运行install-sshd.ps1 以创建 OpenSSH 身份验证代理和 OpenSSH SSH 服务器服务。它还设置了一些权限并注册了事件跟踪 (ETW) 提供程序。

将服务启动更改为自动。OpenSSH SSH Server 服务设置为手动启动,而不是自动:

&sc.exe config sshd start= auto,&sc.exe config ssh-agent start= auto
启动 OpenSSH Authentication Agent 和 SSH Server 服务:
&sc.exe start sshd,&sc.exe start ssh-agent
确保您的 Windows Defender 防火墙已为Port 22 打开,必须启用规则 OpenSSH-Server-In-TCP。如果此规则不可用,请手动建立它:
New-NetFirewallRule  -Name sshd  -DisplayName 'OpenSSH SSH Server'  -Enabled True  -Direction Inbound  -Protocol TCP  -Action Allow  -LocalPort 22  -Program "C:\Windows\System32\OpenSSH\sshd.exe"

替换C:\Windows\System32\OpenSSH\sshd.exe为 sshd.exe 的实际路径(C:\OpenSSH\sshd.exe,如果您遵循此说明)。


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章