GitHub 刪除密碼驗證 @ 2021.08.13


Posted by estella00911 on 2021-08-23

身份驗證失敗

GitHub 修改驗證規則

GitHub 從 2021 年 8 月 13 日開始,不再支援密碼驗證 Git 的使用,改使用 private token-base authentication

GitHub 沒有了密碼驗證,那 Git 要怎麼遠端連結 GitHub 的 repository 呢?就要先創建一個可以連到 GitHub Repository 的 access token。

操作步驟

1. 在 GitHub 創立一個 access token

1.1 GitHub -> settings

1.2 Account settings 的下一欄:Developer settings

1.3 Personal access tokens

點選「Generate new token」。

1.3 建立與設定 private token

可以填寫 token 的說明,並設置完成後,點選「Generate token」。

1.4 安全的儲存產生的新 token

這邊只會出現一次 token,等等要用在登入,先點選紅框將其複製下來。

1.5 將 Git 新增 remote-URL 連到 GitHub Repository

$ git remote set-url origin https://<access_token>@github.com/<UserName>/<repository>.git

<access_token>:剛剛 generate new token
<UserName>:GitHub 使用者名稱
<repository>:GitHub Repository 的名稱

1.5.1 遇到的小問題

按照上面類似的指令輸入,但最後面少輸入了 .git,然後就發現無法連上(fatal),因此使用 git remote -v 來查詢一下, remote URL 是什麼,因為發現連不上,所以後來又使用 git remove -d <name> 刪除掉這個失敗的 remote URL。

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: 'https://github.com/Lidemy/mentor-program-5th-estella00911.git/' 身份驗證失敗
Jean-Lu-2:hw1 jeanlu$ git remote set-url origin https://ghpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFjL7/estella00911/mentor-program-5th-estella00911
Jean-Lu-2:hw1 jeanlu$ git remote-v
git:'remote-v' 不是一個 git 指令。參見 'git --help'。

最類似的指令有
    remote-fd
Jean-Lu-2:hw1 jeanlu$ git remote -v
origin  https://ghpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFjL7/estella00911/mentor-program-5th-estella00911 (fetch)
origin  https://ghpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFjL7/estella00911/mentor-program-5th-estella00911 (push)
Jean-Lu-2:hw1 jeanlu$ git push origin week17
fatal: 無法存取 'https://ghpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFjL7/estella00911/mentor-program-5th-estella00911/':Could not resolve host: ghpxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFjL7
Jean-Lu-2:hw1 jeanlu$ git remote remove origin # 刪除失敗的 remote URL

Jean-Lu-2:hw1 jeanlu$ git remote -v # 檢查有沒有 remote URl 內容,發現沒有任何 remote URL。
Jean-Lu-2:hw1 jeanlu$ git remote add origin  https://github.com/Lidemy/mentor-program-5th-estella00911.git # 加入 remote URL,並在 git 命名為 origin。
Jean-Lu-2:hw1 jeanlu$ git remote -v # 加入後,檢查 remote URL 。
origin  https://github.com/Lidemy/mentor-program-5th-estella00911.git (fetch)
origin  https://github.com/Lidemy/mentor-program-5th-estella00911.git (push)

Jean-Lu-2:hw1 jeanlu$ git push origin week17 # 欲 push 到 origin 的分支 week 17
Username for 'https://github.com': estella00911 # 填寫 username
Password for 'https://estella00911@github.com': # 將剛剛複製的那串 token 貼上。
# 成功 push 上去 GitHub
枚舉物件: 107, 完成.
物件計數中: 100% (107/107), 完成.
使用 4 個執行緒進行壓縮
壓縮物件中: 100% (92/92), 完成.
寫入物件中: 100% (95/95), 1.92 MiB | 2.45 MiB/s, 完成.
總共 95 (差異 25),復用 0 (差異 0),重用包 0
remote: Resolving deltas: 100% (25/25), completed with 8 local objects.
remote:
remote: Create a pull request for 'week17' on GitHub by visiting:
remote:      https://github.com/Lidemy/mentor-program-5th-estella00911/pull/new/week17
remote:
To https://github.com/Lidemy/mentor-program-5th-estella00911.git
 * [new branch]      week17 -> week17

參考:
GitHub support for password authentication was removed
When try to pull or push in GitHub I am getting an error message: “Please use a personal access token instead.”- stackoverflow
Support for password authentication was removed. Please use a personal access token instead


#Github #passwrod-removed #token







Related Posts

[ 筆記 ] JavaScript - 02 函式

[ 筆記 ] JavaScript - 02 函式

筆記、後端資料庫(8-2)理論篇

筆記、後端資料庫(8-2)理論篇

前言

前言


Comments