Skip to content

PlusMagi's Blog By Pitt Phunsanit

Plus emotional magic to the knowledge of logic.

  • About’s Pitt
Close Button

SSH: ให้ mac จำ login with passphrasSSH: ให้ mac จำ login with passphras

2021-02-062021-02-06| phunsanitphunsanit| 0 Comment | 07:00

เป็นขั้นตอนสุดท้ายในการย่อคำสั่ง SSH แล้วคือแทนที่จะมากรอก passphras เราก็ใช้ MacOs กรอก login passphras แทนเรา เมื่อเราเรียก ใช้คำสั่ง อย่าง ssh digitalocean_vps มันจะมีคำถามอยู่ว่า Enter passphrase for key ‘/Users/phunsanit/.ssh/digitalocean_vps‘: คือยังต้องกรอก passphras ให้อยู่นั่นละ แต่อยากจะใช้แค่ ssh digitalocean_vps ก็เข้าไปใน server ได้เลย ก็ทำได้โดยใช้ password manager ของ MacOS Keychain Access


ทำให้ mac ใช้ ssh-agent ให้เองอัตโนมัติ Set and Forget

  1. เปิดไฟล์ Config โดยคำสั่ง
    nano ~/.ssh/config
  2. เพิ่มไว้ บนสุด ของไฟล์
    Host *
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile ~/.ssh/id_rsa
  3. บันทึก
  4. ปิด Terminal แล้วเปิดใหม่

โดย
AddKeysToAgent yes: เมื่อคุณ SSH ครั้งแรกและใส่รหัสผ่าน มันจะจำกุญแจนั้นลง Agent ให้อัตโนมัติ
UseKeychain yes: สำคัญมาก! มันสั่งให้ SSH ไปดึงรหัส Passphrase จาก Apple Keychain มากรอกให้เอง เช่น

# --- digitalocean_vps ---
Host digtalocean AddKeysToAgent yes HostName xx.xx.xxx.xxx IdentityFile ~/.ssh/digitalocean_vps Port 300 UseKeychain yes User B

อย่าลืมแก้ให้ตรงกับที่ใช้

  • Host ชื่อเล่นที่อ้างถึงใน ssh command ไม่ต้องตรงกับชื่อ host จริง ๆ
    ssh digtalocean_vps
  • HostName ip หรือ host name จริง ๆ
  • IdentityFile คือ public key
  • Port ถ้าใช้ port มาตราฐานก็ไม่ต้องใส่
  • UseKeychain ใช้ passphrase
  • User คือ username ที่จะ login

manual add Apple Keychain

  1. add โดยคำสั่งรูปแบบ
    ssh-add --apple-use-keychain ~/.ssh/{key no .pub}
    เช่น
    ssh-add --apple-use-keychain ~/.ssh/digitalocean_vps
  2. ตั้งสิทธิ์ไฟล์
    chmod 600 ~/.ssh/digitalocean_vps
  3. ทดสอบโดยการใช้
    ssh digtalocean_vps

ดู passphras ที่เก็บเอาไว้

  1. เปิดโปรแกรม Keychain Access
    1. กด Command + Spacebar
    2. พิมพ์ว่า Keychain Access แล้วกด Enter
    3. ในช่องค้นหา ให้พิมพ์ชื่อไฟล์กุญแจของคุณ เช่น digitalocean_vps
    4. จะเห็นรายการประมาณว่า SH: /Users/phunsanit/.ssh/digitalocean_vps
  2. กดดูรหัส
    1. ดับเบิ้ลคลิก ที่รายการนั้น
    2. ติ๊ก “Show password”
    3. กรอก รหัสผ่านเข้า mac ของเรา
    4. จะเห็น passphras ที่ safe อยู่

อ่านเพิ่มเติม

  • SSH: ช่วยจำ host โดย .ssh\config
  • SSH: login with passphrase
  • Keyboard Shortcuts ใน Terminal
  • Command Chaining เชื่อมคำสั่ง
Read MoreRead More

Posts pagination

ก่อนหน้า 1 … 497 498 499 … 4,506 ถัดไป

Projects

  • Statement Columns Mapping Helper
  • PlusMagi Site Search
  • PlusMagi Tags Reindex
  • jQuery Plus Repeater

Recent Posts

  • SMR: Small Modular Reactors
  • Project Hail Mary: สองชีวิตต่างโลก กับหนึ่งภารกิจ สะเทือนจักรวาล
  • ขึ้นทางด่วนคุ้มไหม? วิธีตั้งค่า Google Maps คำนวณค่าผ่านทาง เทียบเวลาและค่าน้ำมันให้เห็นชัด ๆ
  • เลิกปวดหัวกับทางลัดมหาภัย: วิธีตั้งค่า Google Maps ให้เลือก “ทางขับง่าย” มากกว่า “เร็วกว่าแค่ 1-2 นาที”
  • OOD: Object-Oriented Design

Archives

Categories

  • .net core (16)
  • AI (52)
  • business (34)
  • Businesses (33)
  • cd (59)
  • ci (62)
  • culture (2)
  • data (5)
  • Design (160)
    • UX/UI (23)
  • devops (200)
  • devsecops (35)
  • dotnet (58)
  • envoy (2)
  • Histories (22)
  • history (2)
  • ios (4)
  • Life (1,210)
    • Books (59)
    • Cartoon (13)
    • Mindset (41)
    • Movies (35)
    • Philosophy (4)
    • Psychology (3)
    • Sci-Fi (53)
    • Tips and Tricks (67)
    • ปรัชญา (267)
    • พัฒนาตนเอง (883)
    • พุทธ (70)
    • สิ่งแวดล้อม (47)
  • mobile (1)
  • mystery (8)
  • net core (10)
  • Network (353)
    • Apache HTTP Server (19)
    • IOT (24)
    • Nginx (41)
    • Stalwart (6)
  • networking (131)
  • Operating Systems (448)
    • Unix-like (313)
      • Android (24)
        • F-Droid (5)
      • Homebrew (22)
      • iPhone (12)
      • Linux (195)
      • macOS (135)
        • OrbStack (12)
      • Oh My ZSH (4)
      • Shell Script (80)
      • SSH (15)
    • Windows (163)
      • PowerShell (28)
      • WSL (25)
  • Programming (1,714)
    • .NET (68)
      • .NET Core EF (7)
      • C# (60)
    • API (145)
      • REST (54)
      • Swagger (13)
    • Database (412)
      • DBeaver (5)
      • MariaDB (38)
      • MySql (81)
      • Oracle Database (8)
        • 10g (3)
      • PostgreSQL (30)
      • RDBMS (78)
      • SQL Server (91)
        • SSMS (10)
        • T-SQL (30)
      • SQLite (2)
    • PowerBuilder (20)
    • Python (27)
    • Rust (44)
    • System Analyst (SA) (97)
    • Testing (110)
      • Automated Testing (45)
        • Playwright (11)
    • UML (53)
    • Web (904)
      • Backend (589)
        • Golang (2)
        • Java (113)
          • Spring Boot (27)
        • Node.js (12)
        • PHP (281)
          • Laravel (60)
          • Yii (5)
      • Frontend (290)
        • CSS (28)
          • Tailwind CSS (6)
        • JavaScript (230)
          • Angular (4)
          • jQuery (70)
          • Tabulator (28)
          • Vue.js (7)
      • WordPress (27)
  • Programs (112)
    • Excel (20)
  • r (2)
  • science (10)
  • script (3)
  • SecDevOps (200)
    • CI/CD (11)
    • Docker (92)
    • GIT (61)
    • SVN (18)
  • Security (370)
  • sistema (1)
  • social (2)
  • system (376)
  • system analyst (31)
  • technology (923)
  • technologyระบบ (101)
  • technologyและระบบ (3)
  • typescript (10)
  • ui (63)
  • Uncategorized (6)
  • ux (58)
  • กฎหมาย (305)
  • การจัดการ (606)
  • การจัดการข้อมูล (351)
  • การจัดการข้อมูลและองค์ความรู้ (3)
  • การพัฒนาตนเอง (12)
  • การออกแบบ (77)
  • ข้อมูล (2)
  • คณิตศาสตร์ (31)
  • ความคิด (110)
  • ความปลอดภัย (224)
  • จริยธรรม (85)
  • จิตวิทยา (885)
  • ชีวิต (115)
  • ทั่วไป (16)
  • ธุรกิจ (622)
  • บุคคล (35)
  • บุคลากร (10)
  • บุคลิก (88)
  • ประวัติศาสตร์ (39)
  • ปัญญาประดิษฐ์ (28)
  • พฤติกรรม (168)
  • ภาษาศาสตร์คอมพิวเตอร์ (28)
  • ระบบ (358)
  • วัฒนธรรม (52)
  • วิชาการ (87)
  • วิชาการข้อมูล (64)
  • วิทยาการข้อมูล (162)
  • วิทยาการข้อมูลและภาษาศาสตร์คอมพิวเตอร์ (1)
  • วิทยาศาสตร์ (164)
  • วิทยาศาสตร์ข้อมูล (28)
  • สังคม (338)
  • สุขภาพ (210)
  • หนังสือ (2)
  • องค์ความรู้ (187)
  • ออกแบบ (18)
  • เทคโนโลยี (291)
  • เทคโนโลยีระบบ (156)
  • 기술 (1)
  • 사회 (1)
  • 시스템 (1)
  • 철학 (1)

Sirat WordPress Theme By VWThemes

Scroll Up
Exit mobile version