GitHub 不能再使用密碼驗證,你有更好的選澤 - SSH Key

GitHub 不能再使用密碼驗證,你有更好的選澤 - SSH Key

目錄

  1. 阿北出事了
  2. 真香!官方教學設定 SSH Key 還有 Token
  3. 曾設定 SSH Key 只要一行 Command 就解決這問題

​

阿北出事了

一如往常地寫完 Code Push 到 GitHub 卻看到以下訊息:

remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

​

remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.

​

fatal: unable to access “…” : The requested URL returned error: 403

​

遇到的當下肯定慌了,不過這其實不是什麼大問題,只是 GitHub 不再支援用密碼去存取你的 Repository, 更精確地說就是從 HTTPS 改用 SSH Key, 而官網也有向使用者解釋:

As previously announced, starting on August 13, 2021, at 09:00 PST, we will no longer accept account passwords when authenticating Git operations on GitHub.com. Instead, token-based authentication (for example, personal access, OAuth, SSH Key, or GitHub App installation token) will be required for all authenticated Git operations.

​

Please refer to this blog post for instructions on what you need to do to continue using git operations securely.

​

Removal

August 13, 2021, at 09:00 PST

​

-HTTPS 和 SSH Key 的差別就像有 FaceID 不用而是手打密碼(誤

在幾年前 Github 還沒被微軟收購時,官方其實是推薦使用 HTTPS,但還是有提供 SSH Key 的連線方式,兩者差別在於:

  • HTTPS:以 Github 來說明,在 Clone 的時候是需要輸入帳號密碼的,如果在 Clone 時並無要求輸入,大部分是因為電腦已經紀錄過帳密就不需要再重新輸入。
  • SSH Key:在電腦中設定好金鑰, Clone 時會經過比對,比對正確才能執行,因此不需要額外的帳號密碼。

兩者執行出來的結果會是一樣的,只是使用的方式不同,設定好 SSH Key 之後要執行 git clone 的時候,就可以使用 Clone via SSH 這個選項。

​

真香!官方教學設定 SSH Key 還有 Token

如果想用 Token 或是還沒設定過 SSH Key,可以參考官方的教學文章:

​

曾設定 SSH Key 只要一行 Command 就解決這問題

Push 左推右推都推不上去,但如果你已經設定過 SSH Key 基本上這個 Command 就解決了:

$ git remote set-url origin [email protected]:{user_id}/{project_name}.git

實際操作範例,參考 Stackoverflow 開發者分享,一開始 Push 遇到這個錯誤

文章配圖

檢視一下 git log 文章配圖

執行上述的 Command 後,記得要把你當前的 Branch 推上去(這裡是 master) 文章配圖

​

Ref

comments powered by Disqus