Built-in SSH Client ปรากฏใน Windows 10 และ Windows Server 2019 Ssh.exe ใช้ Secure Connect ไป Linux/UNIX Servers, VMWare ESXi Hosts และ Devices อื่นๆ แทน Putty, MTPuTTY และ Third-party SSH Clients อื่นๆ Native Windows SSH Client พัฒนาจาก OpenSSH Port และ Pre-installed ใน Windows ตั้งแต่ Windows 10 Build 1809
สารบัญ
- Enable (Install) OpenSSH Client บน Windows 10
- ใช้ Native SSH Client บน Windows 10
- ใช้ SCP.exe Transfer Files ไป/มาจาก Windows Host ผ่าน SSH
Enable (Install) OpenSSH Client บน Windows 10
OpenSSH Client รวมอยู่ใน Windows 10 Features on Demand (เหมือน RSAT) SSH Client Installed By Default บน Windows Server 2019, Windows 10 1809 และ Builds ใหม่กว่า
ตรวจสอบ SSH Client Installed: Get-WindowsCapability -Online | ? Name -like 'OpenSSH.Client*'
ตัวอย่าง OpenSSH Client Installed (State: Installed)
หากยัง (State: Not Present) Install ได้โดย:
- PowerShell:
Add-WindowsCapability -Online -Name OpenSSH.Client* - DISM:
dism /Online /Add-Capability /CapabilityName:OpenSSH.Server~~~~0.0.1.0 - Settings → Apps → Optional Features → Add a feature หา OpenSSH Client คลิก Install
OpenSSH Binary Files อยู่ที่ c:\Windows\System32\OpenSSH\
ssh.exe— SSH Client Executablescp.exe— Tool คัดลอกไฟล์ใน SSH Sessionssh-keygen.exe— Tool Generate RSA SSH Authentication Keysssh-agent.exe— จัดการ RSA Keysssh-add.exe— เพิ่ม Key เข้า SSH Agent Database
ติดตั้ง OpenSSH บน Windows รุ่นก่อนได้: ดาวน์โหลดติดตั้ง Win32-OpenSSH จาก GitHub (ตัวอย่างในบทความ: Configuring SSH FTP on Windows)
ใช้ Native SSH Client บน Windows 10
เริ่ม SSH Client รัน PowerShell หรือ cmd.exe Prompt ดู Options และ Syntax ของ ssh.exe: ssh
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] destination [command]
เชื่อมต่อ Remote Server ด้วย SSH: ssh username@host
หาก SSH Server รันบน Port ต่างจาก Standard TCP/22 ระบุ Port: ssh username@host -p port
ตัวอย่างเชื่อมต่อ Linux Host IP 192.168.1.102 เป็น Root: ssh root@192.168.1.102
ครั้งแรกจะมี Request เพิ่ม Host Key เข้า Trusted List พิมพ์ yes Enter Host Key Fingerprint จะเพิ่มใน C:\Users\username\.ssh\known_hosts
จะถาม Password ใส่ Root Password Remote Linux Server Console จะเปิด (ตัวอย่าง CentOS บน Remote Server)
SSH ใช้เชื่อมต่อทั้ง *Nix OSs และ Windows ในบทความก่อนแสดงวิธีตั้งค่า OpenSSH Server ใน Windows 10 และ Connect จาก Windows Host ด้วย SSH Client
หากใช้ SSH Authentication ด้วย RSA Keys (ดูตัวอย่างตั้งค่า SSH Authentication ใช้ Keys ใน Windows) ระบุ Path ไป Private Key File ใน SSH Client:
ssh root@192.168.1.102 -i "C:\Users\username\.ssh\id_rsa"
เพิ่ม Private Key เข้า SSH-Agent Enable ssh-agent Service ตั้ง Auto Startup:
set-service ssh-agent StartupType 'Automatic'
Start-Service ssh-agent
Add Private Key เข้า SSH-Agent Database: ssh-add "C:\Users\username\.ssh\id_rsa"
ตอนนี้เชื่อมต่อ Server ผ่าน SSH โดยไม่ต้องระบุ Path ไป RSA Key จะใช้ Auto ตอนนี้ Secure Connect เข้า Server ไม่ต้อง Password (หากไม่ได้ Protect RSA Key ด้วย Password อื่น)
ssh root@192.168.1.102
SSH Arguments ที่มีประโยชน์เพิ่มเติม:
-C— Compress Traffic ระหว่าง Client และ Server (ใช้งานได้ใน Slow/Unstable Connections)-v— แสดง Detailed Information ทุก Action ของ SSH Client-R/-L— Forward Ports ผ่าน SSH Tunnel
ใช้ SCP.exe Transfer Files ไป/มาจาก Windows Host ผ่าน SSH
ใช้ Tool scp.exe (ส่วนหนึ่งของ Windows 10 SSH Client Package) คัดลอกไฟล์จาก Computer ไป SSH Server:
scp.exe "E:\ISO\CentOS-8.1.x86_64.iso" root@192.168.1.202:/home
คัดลอก Directory Contents แบบ Recursive: scp -r E:\ISO\ root@192.168.1.202:/home
กลับกัน Transfer File จาก Remote Server มาที่ Computer: scp.exe root@192.168.1.202:/home/CentOS-8.1.x86_64.iso c:\iso
หากตั้งค่า Authentication ด้วย RSA Keys จะไม่ถูกถาม Password ตอน Transfer Files มีประโยชน์หากต้องการตั้งค่า Automatic Scheduled File Copying
ดังนั้นสามารถ SSH เข้า Servers โดยตรงจาก Windows 10 คัดลอกไฟล์ด้วย scp โดยไม่ต้อง Third-party Apps หรือ Tools อื่นๆ