#检测是否安装 ssh-server ssh-client
Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
#启动powershell,在 powershell里执行,安装 server 和 client
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
#设置服务自动启动
Set-Service sshd -StartupType Automatic
Set-Service ssh-agent -StartupType Automatic
Start-Service sshd
Start-Service ssh-agent
#检测ssh服务是否启动
netstat -an | findstr :22
#powershell里执行,将SSH后的CMD换成powershell
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
#在用户组里增加一个用户,可以设置为administrators组,方便ssh登陆
#免密参考下面链接
Get started with OpenSSH | Microsoft Docs
SSH on Windows Server 2019 (including how to sudo) - Raymii.org
Windows Server 2019 SSH Server - 老三的博客 - 博客园