github不再支持用户名密码提交代码问题

325 阅读1分钟

今天向自己的github仓库提交代码时提示如下错误:

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see docs.github.com/en/get-star… for information on currently recommended modes of authentication.
fatal: Authentication failed for 'github.com/shifefiei/s…'

因为自己之前一直是配置SSH keys 和用户名密码来提交代码的。后来才了解到github改变策略了,需要基于token来验证。官方原文如下

In July 2020, we announced our intent to require the use of token-based authentication (for example, a personal access, OAuth, or GitHub App installation token) for all authenticated Git operations. Beginning August 13, 2021, we will no longer accept account passwords when authenticating Git operations on GitHub.com.

Workflows affected

  • Command line Git access
  • Desktop applications using Git (GitHub Desktop is unaffected)
  • Any apps/services that access Git repositories on GitHub.com directly using your password

The following customers remain unaffected by this change:

  • If you have two-factor authentication enabled for your account, you are already required to use token- or SSH-based authentication.
  • If you use GitHub Enterprise Server, we have not announced any changes to our on-premises offering.
  • If you maintain a GitHub App, GitHub Apps do not support password authentication.

所以解决该问题的策略就是如何生成一个自己的 token

一、利用IDEA找到生成入口

  • 找到IDEA的设置入口:IntelliJ IDEA -> Preferences -> Version Control -> GitHub
  • 生成 token 并添加到IDEA中

image.png

image.png

点击 Generate 会跳转的生成页面

image.png 点击生成按钮后会生成一个 token,就是一个以ghp开头的字符串

image.png 请注意这句话:
Make sure to copy your personal access token now. You won’t be able to see it again!
意思是你把token记录下来,刷新网页后你就看不到了!!!

一、登录github直接生成

image.png

Settings -> Developer settings -> Personal access tokens -> Tokens(classic)