1. Problem description
Use the following command to push the code to github
:
git push origin main
Enter the user name and password as prompted, and report the following error:
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.
According to the prompt information, github
removed the support of password authentication in 2021.8.13
personal access token
instead of password authentication. Since the address given in the prompt cannot be accessed, please refer to the relevant documents. The following mainly records how to solve this problem.
2. Solution
github docs The document describes that when using the command line or API, a personal access token should be created instead of a password. The following details how to create personal access token
.
Create a personal access token
- Log in to github
- Click on your avatar in the upper right corner of the page, and then click
Settings
: - In the left sidebar, click Developer Settings:
- In the left sidebar, click Personal Access Token:
- Click Generate new token:
- Give your token a descriptive name:
- To allow your token to expire, select the expiration drop-down menu and click the default value or use the calendar selector:
- Select the scope or permissions you want to grant this token. To use your token to access the repository from the command line, select the repo:
- Click Generate Token:
Warning: Treat your token as a password and keep it secret. When using the API, use tokens as environment variables instead of hard-coding them into your program.
Use tokens on the command line
After obtaining the token, you can enter it instead of the password when performing Git operations over HTTPS.
For example, enter the following in the command line:
$ 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 need to switch the remote from SSH to HTTPS .
If you are not prompted to enter your username and password, your credentials may be cached on your computer. You can update keychain credentials to use tokens to replace the old password.
Configure github credentials in windows
To https
, you need to manually enter the user name and personal access token
each time. For convenience, you can use the credential manager in windows to save the relevant configuration, as shown in the following figure:
If the github credentials already exist, the user name and password are saved originally, and the original password needs to be changed to personal access token
. Normally, we will save the relevant credentials here after logging in to github. If not available, create them manually, as shown in the figure below. Shown:
Reference documents:
https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。