文章目录

  • ​​前言​​
  • ​​一、需求背景环境​​
  • ​​一、问题描述​​
  • ​​1、 截图​​
  • ​​2、报错信息解读​​
  • ​​二、寻找破解之法​​
  • ​​1、进入网址​​
  • ​​2、创建个人访问token​​
  • ​​3、两种token类型​​
  • ​​三、创建细粒度个人访问令牌​​
  • ​​1. 观看网址​​
  • ​​2、创建过程​​
  • ​​四、使用token测试​​

前言

  • 好久没有上传代码到GitHub了,没想到突然报错了,上了网上一搜,才知道,21年8月13号更新了,不再使用密码,开始使用token令牌代替密码。
  • 网上的资料我也尝试了一下,都不行,没办法,只能研究了,用时两小时,完美解决问题,特来记录一下。

一、需求背景环境

  1. win10系统
  2. 本地创建仓库,将代码push到GitHub上,然后报错。

一、问题描述

1、 截图

github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._git

2、报错信息解读

冯坚持@LAPTOP-8MBP8VBI MINGW64 /d/Users/IDEA/user_manager_front_back (main)
$ git push -u origin main
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/fengfanli/front-and-back.git/'

解读:

远程:支持密码认证已于2021年8月13日删除。
远程:请看 网址(​​​https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls​​)有关当前推荐的身份验证模式的信息

即,从这个网址中去寻找方法,然后都是英文,但也只能硬着头皮去看了。

二、寻找破解之法

1、进入网址

进入网址:​​https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls​

github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._github_02


此页主题是:​​关于远程仓库​

定位到关键的点,如下图:

github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._细粒度_03


通过上图中箭头所指的链接去 创建个人访问token

2、创建个人访问token

  1. 点进入网址后如下: ​​https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token​
  2. github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._git_04


  3. 第一句话就说出来了:

You can create a personal access token to use in place of a password with the command line or with the API.
意思是:
​​​创建个人访问token去使用代替密码在命令行中。​

3、两种token类型

从上面的截图中的最右边可以看到有两种token类型,

  1. 第一种是​​fine-grained personal access token​​,即细粒度个人访问令牌
  2. 第二种是​​personal access token (classic)​​,即个人访问令牌(分类化)
  • 从字面意义上,第一种是细粒度的token,使用过后可以发现,可以对一个仓库设置一个token,还可以设置每一个permission(权限),粒度比较细。
  • 第二个没有细研究,有会的大佬可以评论指正,一起学习

三、创建细粒度个人访问令牌

1. 观看网址

从下面的网址中可以看出,已经给出创建过程,但都是英文,直接看3.2吧

github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._github_05


github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._github_06

2、创建过程

  1. 进入GitHub的​​setting​​。
  2. github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._github_07

  3. 最左边的最下面,进入​​Developer settings​
  4. github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._github_08

  5. 点击​​Personal access tokens ​​ 中的 ​​Fine-grained tokens​
  6. github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._git_09

  7. 点击 ​​Generate new token​
  8. github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._细粒度_10


  9. github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._细粒度_11


  10. github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._github_12


  11. github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._github_13

  12. 细节如下:
  • Token name: 令牌名称
  • Expiration:令牌过期时间
  • Description:描述
  • Resource owner:资源的owner
    ​​Repository access​​:仓库访问,设置所有仓库使用一个token,还是一个仓库一个token,​我这里选择第二个,所有仓库使用一个token
  • Permissions: 权限,​Repository permissions 中的权限我都选中了。
  • 最后点击创建即可,生成下面的token,​使用token替换 push命令中的密码即可​​(token自己保存,刷新后就没了)

四、使用token测试

  1. 创建一个仓库,会看到这些命令,按顺序执行即可,在最后一个命令输入你的用户名,密码就是上面创建的token。

    git init
    git add README.md
    git commit -m "first commit"
    git branch -M main
    git remote add origin https://github.com/fengfanli/front-and-back.git
    git push -u origin main
  2. 执行最后一个命令
    输入用户名:
  3. github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._github_14

  4. 输入密码:
  5. github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._细粒度_15

  6. push 成功
  7. github报错(完美解决):获取token。remote: Support for password authentication was removed on August 13, 2021._细粒度_16