您现在的位置是:首页 >技术杂谈 >GitHub: Support for password authentication was removed on August 13, 2021网站首页技术杂谈

GitHub: Support for password authentication was removed on August 13, 2021

Yongqiang Cheng 2023-05-19 00:00:03
简介GitHub: Support for password authentication was removed on August 13, 2021

GitHub: Support for password authentication was removed on August 13, 2021

1 Description

yongqiang@yongqiang:~/yongqiang_work/kmeans$ git push origin master
Username for 'https://github.com': ******@163.com
Password for 'https://******@163.com@github.com':
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/ForeverStrongCheng/kmeans.git/'
yongqiang@yongqiang:~/yongqiang_work/kmeans$

2 Creating a personal access token (创建个人访问令牌)

Use a personal access token in place of a password when authenticating to GitHub in the command line or with the API.
使用 personal access token 代替密码。

2.1 About personal access tokens

Personal access tokens are an alternative to using passwords for authentication to GitHub when using the GitHub API or the command line.
使用 GitHub API 或命令行时,可使用 Personal access token 替代密码向 GitHub 进行身份验证。

GitHub currently supports two types of personal access tokens: fine-grained personal access tokens and personal access tokens (classic). GitHub recommends that you use fine-grained personal access tokens instead of personal access tokens (classic) whenever possible.
GitHub 目前支持两种类型的 personal access token:fine-grained personal access token 和 personal access tokens (classic)。GitHub 建议尽可能使用 fine-grained personal access token 而不是 personal access tokens (classic)。

  1. In the upper-right corner of any page, click your profile photo, then click Settings.

在这里插入图片描述

  1. In the left sidebar, click Developer settings.
  2. In the left sidebar, under Personal access tokens, click Tokens (classic).
  3. Select Generate new token, then click Generate new token (classic).

在这里插入图片描述

  1. Give your token a descriptive name.
  2. To give your token an expiration, select the Expiration drop-down menu, then click a default or use the calendar picker.

在这里插入图片描述

  1. Select the scopes you’d like to grant this token. To use your token to access repositories from the command line, select repo. A token with no assigned scopes can only access public information.
    选择要授予此令牌的作用域。若要使用令牌从命令行访问存储库,请选择 repo。没有指定范围的令牌只能访问公共信息。
  2. Click Generate token.

在这里插入图片描述

在这里插入图片描述

2.2 Using a personal access token on the command line (在命令行上使用 personal access token)

Once you have a token, you can enter it instead of your password when performing Git operations over HTTPS.
如果你有令牌,则可以在通过 HTTPS 执行 Git 操作时输入令牌,而不是密码。

For example, on the command line you would enter the following:

$ git clone https://github.com/USERNAME/REPO.git
Username: YOUR_USERNAME
Password: YOUR_TOKEN

Personal access tokens can only be used for HTTPS Git operations. If your repository uses an SSH remote URL, you will need to switch the remote from SSH to HTTPS.
Personal access token 只能用于 HTTPS Git 操作。如果存储库使用 SSH 远程 URL,则需要将远程 URL 从 SSH 切换到 HTTPS。

If you are not prompted for your username and password, your credentials may be cached on your computer. You can update your credentials in the Keychain to replace your old password with the token.
如果没有提示你输入用户名和密码,说明您的凭据可能已缓存在计算机上。可在密钥链中更新凭据,从而用令牌替换旧密码。

3 在要求输入密码的位置改为输入生成的 token

yongqiang@yongqiang:~/yongqiang_work/kmeans$ git push origin master
Username for 'https://github.com': chengyq116@163.com
Password for 'https://chengyq116@163.com@github.com':
Everything up-to-date
yongqiang@yongqiang:~/yongqiang_work/kmeans$

References

https://yongqiang.blog.csdn.net/
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。