本篇文章參考官方文件在 Windows 安裝 SSH 伺服器

使用系統管理員身分執行 PowerShell

開始搜尋 PowerShel,並按右鍵使用系統管理員身分執行

使用 PowerShell 安裝 OpenSSH

1
2
3
4
5
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

啟動 OpenSSH 伺服器

1
2
# Start the sshd service
Start-Service sshd

設定開機自動啟動伺服器

參考連結

1
2
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'

設定 SSH 伺服器防火牆

1
2
3
4
5
6
7
# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}

檔案路徑

部署公開金鑰位置

參考文件

一般使用者公開金鑰位置

1
%USERPROFILE%\.ssh\authorized_keys

系統管理使用者公開金鑰位置

1
%ALLUSERSPROFILE%\ssh\administrators_authorized_keys

系統管理使用者 sshd_config 位置

1
%ALLUSERSPROFILE%\ssh\sshd_config

OpenSSH 安裝位置

1
%SystemRoot%\System32\OpenSSH