GitHub使用Personal access token


報錯: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/sober-orange/study.git/': The requested URL returned error: 403

原因:自2021年8月13日起,github不再支持使用密碼push的方式


解決方案:兩種
一、 使用SSH
二、使用Personal access token

法一:使用SSH

點擊此鏈接跳轉至方法詳情

法二:使用Personal access token

首先,需要獲取token

  1. 點擊你的GitHub頭像 -> 設置 -> 開發者設置 -> Personal access tokens -> Generate new token

  2. 生成token

  3. 復制token

  4. 使用token進行push、pull、clone等操作(pull和clone等操作原理同push,只需替換push為pull或其他相應的命令即可)
    使用token的方式其實原理在於將原來明文密碼換為token,說白了就是token>=password,之所以我這里寫了>號,是因為token的功能遠大於原來的password,相比password,token具有很多其沒有的用法。
    我將使用token的方法進行了細分,以滿足不同的使用要求。請各位根據自己的使用情況進行選擇

    token法一:直接push

    此方法每次push都需要輸一遍token,很是費勁啊

     
    # git push https://你的token@你的倉庫鏈接,我這里是我的倉庫鏈接你要改成你的 git push https://你的token@github.com/sober-orange/study.git 

    token法二:修改remote別名

    這種方式在push的時候直接指明別名就可
    如果你已經設置過remote別名,使用如下命令

     
    # 我這里的別名是origin # git remote set-url 你的remote別名 https://你的token@你的倉庫地址 git remote set-url origin https://你的token@github.com/sober-orange/study.git # 提交代碼 git push -u origin master 

    如果你未設置過別名,使用如下命令添加別名

     
    # git remote add 別名 https://你的token@你的倉庫地址 git remote add origin https://你的token@github.com/sober-orange/study.git # 提交代碼 git push -u origin master 

    token法三:使用Git Credential Manager Core (GCM Core) 記住token

     
    git push
    Username: 你的用戶名
    Password: 你的token
    # 記住token git config credential.helper store 

    toekn法四:使用Windows的憑據管理器

    1. 打開憑據管理器 -> windows憑據
    2. 找到“git:https://github.com”的條目,編輯它
    3. 用token替換你以前的密碼

參考文獻


https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token


https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM