天天看點

github push代碼報錯remote: Support for password authentication was removed on August 13, 2021.一、 問題描述二、 github為什麼要把密碼換成token

一、 問題描述

如果你在七夕(沒錯就是2021年8月14日)的這一天剛好加班,又剛好去通路了全球最大的同性交友網站,又剛好去更新送出代碼,又或你建立了一個新的倉庫送給自己,又剛好想把這個倉庫送給(push)github,你就剛好會遇到這個問題:

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

具體如下:

(yolov4) [email protected]:~/shl_res/5_new_project/Yolov4_DeepSocial$ git push origin master
Username for 'https://github.com': shliang0603
Password for 'https://[email protected]': 
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 'https://github.com/shliang0603/Yolov4_DeepSocial.git/': The requested URL returned error: 403
(yolov4) [email protected]:~/shl_res/5_new_project/Yolov4_DeepSocial$ 
           

納尼?老夫就是許久沒有建倉,這是什麼情況,大概意思就是你原先的密碼憑證從2021年8月13日開始就不能用了,必須使用個人通路令牌(

personal access token

),就是把你的密碼替換成

token

二、 github為什麼要把密碼換成token

github官方解釋

1、修改為token的動機

我們描述了我們的動機,因為我們宣布了對 API 身份驗證的類似更改,如下所示:

近年來,GitHub 客戶受益于 GitHub.com 的許多安全增強功能,例如雙因素身份驗證、登入警報、經過驗證的裝置、防止使用洩露密碼和 WebAuthn 支援。 這些功能使攻擊者更難擷取在多個網站上重複使用的密碼并使用它來嘗試通路您的 GitHub 帳戶。 盡管有這些改進,但由于曆史原因,未啟用雙因素身份驗證的客戶仍能夠僅使用其GitHub 使用者名和密碼繼續對 Git 和 API 操作進行身份驗證。

從 2021 年 8 月 13 日開始,我們将在對 Git 操作進行身份驗證時不再接受帳戶密碼,并将要求使用基于令牌(token)的身份驗證,例如個人通路令牌(針對開發人員)或 OAuth 或 GitHub 應用程式安裝令牌(針對內建商) GitHub.com 上所有經過身份驗證的 Git 操作。 您也可以繼續在您喜歡的地方使用 SSH 密鑰(如果你要使用ssh密鑰可以參考)。

2、修改為token的好處

令牌(token)與基于密碼的身份驗證相比,令牌提供了許多安全優勢:

  • 唯一: 令牌特定于 GitHub,可以按使用或按裝置生成
  • 可撤銷:可以随時單獨撤銷令牌,而無需更新未受影響的憑據
  • 有限 : 令牌可以縮小範圍以僅允許用例所需的通路
  • 随機:令牌不需要記住或定期輸入的更簡單密碼可能會受到的字典類型或蠻力嘗試的影響

三、 如何生成自己的token

1、在個人設定頁面,找到Setting(參考)

github push代碼報錯remote: Support for password authentication was removed on August 13, 2021.一、 問題描述二、 github為什麼要把密碼換成token

2、選擇開發者設定

Developer setting

github push代碼報錯remote: Support for password authentication was removed on August 13, 2021.一、 問題描述二、 github為什麼要把密碼換成token

3、選擇個人通路令牌

Personal access tokens

,然後選中生成令牌

Generate new token

github push代碼報錯remote: Support for password authentication was removed on August 13, 2021.一、 問題描述二、 github為什麼要把密碼換成token

4、設定token的有效期,通路權限等

github push代碼報錯remote: Support for password authentication was removed on August 13, 2021.一、 問題描述二、 github為什麼要把密碼換成token

選擇要授予此令牌token的範圍或權限。

要使用token從指令行通路倉庫,請選擇repo。

要使用token從指令行删除倉庫,請選擇delete_repo

其他根據需要進行勾選

5、生成令牌Generate token

github push代碼報錯remote: Support for password authentication was removed on August 13, 2021.一、 問題描述二、 github為什麼要把密碼換成token

如下是生成的token

github push代碼報錯remote: Support for password authentication was removed on August 13, 2021.一、 問題描述二、 github為什麼要把密碼換成token

注意:

記得把你的token儲存下來,因為你再次重新整理網頁的時候,你已經沒有辦法看到它了,是以我還沒有徹底搞清楚這個token的使用,後續還會繼續探索!

github push代碼報錯remote: Support for password authentication was removed on August 13, 2021.一、 問題描述二、 github為什麼要把密碼換成token

6、之後用自己生成的token登入,把上面生成的token粘貼到輸入密碼的位置,然後成功push代碼!

github push代碼報錯remote: Support for password authentication was removed on August 13, 2021.一、 問題描述二、 github為什麼要把密碼換成token

也可以 把token直接添加遠端倉庫連結中,這樣就可以避免同一個倉庫每次送出代碼都要輸入token了:

git remote set-url origin https://<your_token>@github.com/<USERNAME>/<REPO>.git
           

<your_token>

:換成你自己得到的token

<USERNAME>

:是你自己github的使用者名

<REPO>

:是你的倉庫名稱

例如:

git remote set-url origin https://[email protected]/RichardoMrMu/class_yolov5_head.git
           

四、 常見問題

1、如果 push 等操作沒有出現輸入密碼選項,請先輸入如下指令,之後就可以看到輸入密碼選項了

git config --system --unset credential.helper