เมื่อเจอ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! ตอน ที่ pull code หรือ push code

Phatcharaphan Ananpreechakun
odds.team
Published in
2 min readMar 24, 2023

เมื่อเจอ error แบบนี้ในตอนที่ pull code หรือ push code

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s.
Please contact your system administrator.
Add correct host key in /Users/phatpan/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/phatpan/.ssh/known_hosts:7
Host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

เกิดจาก host key ของ remote server เปลี่ยนดังนั้นเราก็ต้องแก้ไข

เริ่มมาแก้ไขดังนี้

  1. เปิด Terminal
  2. เข้าไปยัง folder .ssh
cd ~/.ssh

3. เปิดไฟล์ known_hosts file ใน folder .ssh และทำการเปิดเพื่อแก้ไข

vi known_hosts

4. ใน case ที่เกิด error นั้นจะเป็น github.com ให้ทำการ search ใน ไฟล์นั้นด้วย github.com และทำการลบบรรทัดนั้นด้วยกดใน keyboard dสองรอบ จะทำการลบบรรทัดนั้น หลังจากนั้นกด keyboard :wq! เพื่อออกจาก vi และทำการ save ข้อมูล

5. ไปยัง source code ที่เราต้องการ pull code or push code อีกรอบ เพื่อทำการเชื่อมต่อ remote host อีกรอบ หลังจากนั้นจะมี prompted ให้ทำการ accept new RSA key ของ host อีกรอบ ให้ทำการกด yes เพื่อทำการเพิ่ม key ใหม่ใน known_hosts file และ เชื่อมต่อกับ remote host

แค่นี้ก็เสร็จแล้ว ^-^

หวังว่าจะมีประโยชน์กับคนที่เจอ error แบบนี้น๊า

เจอกันใหม่บทความหน้า

--

--