关于Support for password authentication was removed on August 13, 2021报错的解决方案

好久没有往Github提交代码了,今天偶然提交代码的时候给报了一个remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.的错误,错误提示如下。

(yolov4) shl@zhihui-mint:~/shl_res/5_new_project/Yolov4_DeepSocial$ git push origin master
Username for 'https://github.com': shliang0603
Password for 'https://shliang0603@github.com': 
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/shliang0603/Yolov4_DeepSocial.git/': The requested URL returned error: 403
(yolov4) shl@zhihui-mint:~/shl_res/5_new_project/Yolov4_DeepSocial$

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

为什么要把密码换成token

下面是Github官方的解释: 近年来,GitHub 客户受益于 GitHub.com 的许多安全增强功能,例如双因素身份验证、登录警报、经过验证的设备、防止使用泄露密码和 WebAuthn 支持。 这些功能使攻击者更难获取在多个网站上重复使用的密码并使用它来尝试访问您的 GitHub 帐户。 尽管有这些改进,但由于历史原因,未启用双因素身份验证的客户仍能够仅使用其GitHub 用户名和密码继续对 Git 和 API 操作进行身份验证。

从 2021 年 8 月 13 日开始,我们将在对 Git 操作进行身份验证时不再接受帐户密码,并将要求使用基于令牌(token)的身份验证,例如个人访问令牌(针对开发人员)或 OAuth 或 GitHub 应用程序安装令牌(针对集成商) GitHub.com 上所有经过身份验证的 Git 操作。 您也可以继续在您喜欢的地方使用 SSH 密钥(如果你要使用ssh密钥可以参考)。

修改为token的好处:

令牌(token)与基于密码的身份验证相比,令牌提供了许多安全优势: - 唯一: 令牌特定于 GitHub,可以按使用或按设备生成 - 可撤销:可以随时单独撤销令牌,而无需更新未受影响的凭据 - 有限 : 令牌可以缩小范围以仅允许用例所需的访问 - 随机:令牌不需要记住或定期输入的更简单密码可能会受到的字典类型或蛮力尝试的影响

如何生成token

1,打开Github,在个人设置页面,找到【Setting】,然后打开找到【Devloper Settting】,如下图。

然后,选择个人访问令牌【Personal access tokens】,然后选中生成令牌【Generate new token】。

在上个步骤中,选择要授予此令牌token的范围或权限。

  • 要使用token从命令行访问仓库,请选择repo
  • 要使用token从命令行删除仓库,请选择delete_repo
  • 其他根据需要进行勾选

然后,点击【Generate token】生成令牌。

生成token后,记得把你的token保存下来,以便进行后面的操作。把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://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@github.com/shliang0603/Yolov4_DeepSocial.git/

编辑于 2021-09-26 09:10