remote Support for password authentication was removed on August 13, 2021

remote Support for password authentication was removed on August 13, 2021

本文主要介绍 github 开发人员在七夕搞事情:remote: Support for password authentication was removed on August 13, 2021.

问题描述

如果你在七夕(没错就是 2021 年 8 月 14 日)的这一天刚好加班,又刚好去访问了全球最大的同性交友网站,又刚好去更新提交代码,又或你创建了一个新的仓库送给自己,又刚好想把这个仓库送给(push)github,你就刚好会遇到这个问题:remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

具体如下:

1
2
3
4
$ git push
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: Authentication failed for 'https://github.com/MrSeaWave/blogs.git/'

这是什么情况,大概意思就是你原先的密码凭证从2021年8月13日开始就不能用了,必须使用个人访问令牌(personal access token),就是把你的密码替换成token

github 为什么要把密码换成 token

官方解释

修改为 token 的好处

令牌(token)与基于密码的身份验证相比,令牌提供了许多安全优势:

  1. 唯一: 令牌特定于 GitHub,可以按使用或按设备生成

  2. 可撤销:可以随时单独撤销令牌,而无需更新未受影响的凭据

  3. 有限 : 令牌可以缩小范围以仅允许用例所需的访问

  4. 随机:令牌不需要记住或定期输入的更简单密码可能会受到的字典类型或蛮力尝试的影响

如何生成自己的 token

  1. 个人设置页面,找到Setting 链接

    image-20210829121216988

2、选择设置Developer setting,选择个人访问令牌Personal access tokens,然后选中生成令牌Generate new token

image-20210829121349085

  1. 设置 token 的有效期,访问权限等

    选择要授予此令牌token范围权限

  • 要使用token从命令行访问仓库,请选择repo

  • 要使用token从命令行删除仓库,请选择delete_repo

  • 其他根据需要进行勾选

    image-20210829121516730

  1. 生成令牌Generate token

    image-20210829121622426

    image-20210829121750465

    注意:记得及时把你的 token 保存下来,因为你再次刷新网页的时候,你已经没有办法看到它了

  2. 之后用自己生成的token登录,把上面生成的token粘贴到输入密码的位置,然后成功push代码!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ git push
Username for 'https://github.com': MrSeaWave
Password for 'https://MrSeaWave@github.com':
husky > pre-push (node v14.17.5)
---- push files ----
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 4 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 755 bytes | 755.00 KiB/s, done.
Total 6 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To https://github.com/MrSeaWave/blogs.git
5162910..388fa6f master -> master

也可以 把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://ghp_LJGJUevVou3FXXXXXXXXXXXXXX@github.com/MrSeaWave/blogs/

FAQ

  1. 如果 push 等操作没有出现输入密码选项,请先输入如下命令,之后就可以看到输入密码选项了

    git config --system --unset credential.helper

  2. SourceTree也遇到类似问题

    SourceTree提交时遇到:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    Pushing to https://github.com/MrSeaWave/MacApp.git
    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: Authentication failed for 'https://github.com/MrSeaWave/MacApp.git/'
    Pushing to https://github.com/MrSeaWave/MacApp.git
    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: Authentication failed for 'https://github.com/MrSeaWave/MacApp.git/'
    Pushing to https://github.com/MrSeaWave/MacApp.git
    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: Authentication failed for 'https://github.com/MrSeaWave/MacApp.git/'
    Pushing to https://github.com/MrSeaWave/MacApp.git
    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: Authentication failed for 'https://github.com/MrSeaWave/MacApp.git/'
    1. 可以git remote set-url origin https://<your_token>@github.com/<USERNAME>/<REPO>.git

    2. 也可以:(密码处填写token

    image-20210829125142006

    参考链接

  3. Token authentication requirements for Git operations

  4. Creating a personal access token

  5. github 开发人员在七夕搞事情:remote: Support for password authentication was removed on August 13, 2021.

  6. GitHub 不再支持密码验证解决方案:SSH 免密与 Token 登录配置

remote Support for password authentication was removed on August 13, 2021

https://hailangya.com/articles/2021/08/29/github-login-token/

作者

Sea

发布于

2021-08-29

更新于

2023-01-10

许可协议

评论