Windows 10 1809+ และ Server 2019+ มี OpenSSH Server Built-in (Feature on Demand) ติดตั้งง่าย ไม่ต้องโหลดจาก GitHub
ติดตั้ง OpenSSH Server
PowerShell: Add-WindowsCapability -Online -Name OpenSSH.Server*
DISM: dism /Online /Add-Capability /CapabilityName:OpenSSH.Server~~~~0.0.1.0
GUI: Settings → Apps → Optional Features → Add a feature → Open SSH Server → Install
ตรวจสอบ: Get-WindowsCapability -Online | ? Name -like 'OpenSSH.Ser*' → State: Installed
ตั้งค่า SSH Service
Set-Service -Name sshd -StartupType 'Automatic'
Start-Service sshd
เช็ค Port 22: netstat -na | find ":22"
Firewall Rule: Get-NetFirewallRule -Name *OpenSSH-Server* → Enabled=True
ถ้าไม่มี/Disable: New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Path สำคัญ:
- Executables:
C:\Windows\System32\OpenSSH\ - sshd_config:
C:\ProgramData\ssh\(สร้างหลัง Start ครั้งแรก) - Log:
C:\windows\system32\OpenSSH\logs\sshd.log - Keys:
%USERPROFILE%\.ssh\
User `sshd` ถูกสร้างอัตโนมัติ
Config sshd_config
Edit %programdata%\ssh\sshd_config
# Deny specific user/group
DenyUsers woshub\admin@192.168.1.10
DenyUsers corp\*
AllowGroups woshub\sshadmins
AllowGroups sshadmins
DenyGroups Administrators
# Auth methods
PubkeyAuthentication yes
PasswordAuthentication yes
# Change Port
Port 22
Restart: restart-service sshd
เชื่อมต่อ SSH ไป Windows
PuTTY หรือ Built-in SSH Client (ssh user@ip)
Login → cmd.exe Shell
รันคำสั่ง/Script ได้
ใช้ PowerShell: powershell.exe
ตั้ง Default Shell = PowerShell:
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String –Force
Reconnect → PS Prompt (PS C:\Users\admin>) Tab Completion, Colors, History ทำงานครบ Admin = Elevated Session แม้ UAC On