Try   HackMD

Git 推送時一直要求輸入帳密怎麼辦?

今天要將本機的內容推送(Push)到 GitHub 上的遠端儲存庫時,卻要求已經設定 SSH 認證的我輸入帳號及密碼,怎麼會這樣?

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

上網爬文一下,發現了問題的原因,在於 clone 時選到 HTTPS 的網址,因此 clone 下來的儲存庫會將遠端(remote)也設為 HTTPS,導致推送時無法以 SSH 進行身分認證。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

解決方式:將遠端儲存庫的位址更改為 SSH 格式
git remote set-url origin(或你自訂的名稱) git@github.com:<Username>/<Project>.git 就解決啦。

也許你會想,那照著輸入帳密不就行了?但由於傳統輸入帳號密碼的認證方式有安全問題,GitHub 已經預告要停止使用此認證方式,並呼籲使用者們改用 Token(代符)方式登入

這樣又可以繼續開心用 Yubikey 來處理認證啦~

Reference
Push to GitHub without a password using ssh-key

tags: 隨手寫寫 開發札記 Git