一如往常地寫完 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
在幾年前 Github 還沒被微軟收購時,官方其實是推薦使用 HTTPS,但還是有提供 SSH Key 的連線方式,兩者差別在於:
兩者執行出來的結果會是一樣的,只是使用的方式不同,設定好 SSH Key 之後要執行 git clone
的時候,就可以使用 Clone via SSH 這個選項。
如果想用 Token 或是還沒設定過 SSH Key,可以參考官方的教學文章:
Push 左推右推都推不上去,但如果你已經設定過 SSH Key 基本上這個 Command 就解決了:
$ git remote set-url origin [email protected]:{user_id}/{project_name}.git
實際操作範例,參考 Stackoverflow 開發者分享,一開始 Push 遇到這個錯誤
檢視一下 git log
執行上述的 Command 後,記得要把你當前的 Branch 推上去(這裡是 master)