Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบ >> Windows Server

เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

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

เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

ตรวจสอบ: Get-WindowsCapability -Online | ? Name -like 'OpenSSH.Ser*' → State: Installed

เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

ตั้งค่า SSH Service

Set-Service -Name sshd -StartupType 'Automatic'
Start-Service sshd
เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

เช็ค Port 22: netstat -na | find ":22"

เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

Firewall Rule: Get-NetFirewallRule -Name *OpenSSH-Server* → Enabled=True

เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

ถ้าไม่มี/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
เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

Restart: restart-service sshd

เชื่อมต่อ SSH ไป Windows

PuTTY หรือ Built-in SSH Client (ssh user@ip)

เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

Login → cmd.exe Shell

เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+) เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

รันคำสั่ง/Script ได้

เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

ใช้ PowerShell: powershell.exe

เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

ตั้ง Default Shell = PowerShell:

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String –Force
เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)

Reconnect → PS Prompt (PS C:\Users\admin>) Tab Completion, Colors, History ทำงานครบ Admin = Elevated Session แม้ UAC On

เชื่อมต่อ Windows ผ่าน SSH ด้วย Built-in OpenSSH Server (Win 10 1809+/Server 2019+)