解決 GitHub 無法 push,出現403問題 ( Git Push To Repository Key Username and Password Error )

介紹如何透過 GitHub Personal Access Tokens 解決 MacOS 無法 push 出現 403 問題

Austin7L
2 min readSep 20, 2023

前言:使用 MacOS 搭配 GitHub 推送 Code 至 Repository 遇上需輸入帳號密碼驗證,但輸入正常可登入 GitHub 帳密後卻始終出現
fatal: Authentication failed for ‘ https://github.com/<userName>/iOSAppDev.git/ '

MacBook-Pro:Development appdev$ git push -u origin main
Username for 'https://github.com': <your github user name>
Password for 'https://austin7l@github.com': <your github user password>
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/austin7l/iOSAppDev.git/'

Step 1 : 確認 remote 是正確的

MacBook-Pro:Development appdev$ git remote -v
origin https://github.com/Austin7L/iOSAppDev.git (fetch)
origin https://github.com/Austin7L/iOSAppDev.git (push)

Step 2 : 建立 GitHub Personal Access Token

若需要 圖文並茂 請點連結,以下以文字說明。

  1. 於 GitHub 介面點擊個人頭像後選擇 setting
  2. setting 頁面選擇 Developer settings
  3. 於 Personal access tokens 選單中選到 Tokens ( classic )
  4. 建立 New token,點擊 Generate new token ( Generate new token ( classic ) )
  5. 輸入 Note、Expiration、Select repo scopes
  6. 點擊 Generate token,會自動產生一個 token
  7. 複製 Token 回到 Terminal 重新 Push
  8. 輸入 Username 和 Password,密碼使用剛複製的 Token
MacBook-Pro:Development appdev$ git push -u origin main
Username for 'https://github.com': <your github user name>
Password for 'https://Austin7L@github.com': <paste the token what you create>
Enumerating objects: 2, done.
Counting objects: 100% (2/2), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 249 bytes | 249.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/Austin7L/iOSAppDev.git
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

--

--

Austin7L

I'm Austin, enjoy learning different programing skills