Wednesday, February 18, 2026

ทบทวนสร้าง private key for remote ssh server

Server Linux Ubuntu

Client Windows 11

  • เปิด power shell

> ssh-keygen -t ed25519 -C "your_email@example.com"

  • ถ้าถาม  key ก็ enter ผ่านไปเลยไม่ต้องใส่ก็ได้ จะได้ไฟล์อยู่ที่
  • C:\Users\YourName\.ssh\
  • id_ed25519 -> private key
  • id_ed25519.pub - > public key
  • นำ Public Key ไปไว้ที่ Server (ฝั่ง Linux)
  • เปิดไฟล์  C:\Users\YourName\.ssh\id_ed25519.pub ใน notepad และ คัดลอก เนื้อหาใน public key ในนั้นไว้
  • จากนั้น remote linux server  วางเนื้อหา  public key ที่คัดลอกไว้จากฝั่ง client  

~/.ssh/authorized_keys

  • และบันทึกไฟล์ที่ server ให้เรียบร้อย
  • ทดสอบ ssh ฝั่ง windows client โดยเปิด power shell

> ssh user@remotehost 

Client Linux หรือ MacOS

$ ssh-keygen -t ed25519 -C "your_email@example.com"

ขั้นตอนการตอบคำถาม:

  1. ระบบจะถามที่เก็บไฟล์ (Enter file in which to save the key): ให้กด Enter เพื่อใช้ค่าเริ่มต้น (/Users/yourname/.ssh/id_ed25519)

  2. ระบบจะถาม Passphrase: แนะนำให้ตั้งรหัสผ่านสั้นๆ เพื่อล็อคไฟล์ Key ไว้ (หรือกด Enter ข้ามไปเลยถ้าไม่ต้องการ)

$ ssh-copy-id -i ~/.ssh/id_ed25519.pub username@server_ip
  • หลังจากนั้น Key จะถูกไปวางแบบ appendใน ~/.ssh/authorized_keys บน Server ให้ทันที
  • ทดสอบ ssh remote host ได้เลย หรือ ใช้ vscode remote ssh ได้เลย โดยใช้ private key เข้าระบบได้เลย

No comments:

Post a Comment

Popular Posts