没有不值得去解决的问题,也没有不值得去学习的技术!

Configure GitHub SSH Key and Personal Access Token on Windows 10 When Git Push Fails Host Verification

When running the command: git push -u origin master, the following prompt appears: The authenticity of host 'github.com (52.192.72.89)' can't be established.ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.

1. When running the command: git push -u origin master, the following prompt appears: The authenticity of host ‘github.com (52.192.72.89)’ can’t be established.ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM. As shown in Figure 1

When running the command: git push -u origin master, the following prompt appears: The authenticity of host 'github.com (52.192.72.89)' can't be established.ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Figure 1
Plaintext

PS E:\wwwroot\Laravel-8> git remote add origin git@github.com:shuijingwan/hello_laravel.git                             
PS E:\wwwroot\Laravel-8> git push -u origin master
The authenticity of host 'github.com (52.192.72.89)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no)? no
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
PS E:\wwwroot\Laravel-8> git push -u origin master
The authenticity of host 'github.com (52.69.186.44)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.69.186.44' (ECDSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
PS E:\wwwroot\Laravel-8> git push -u origin master
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

2. Pushing via TortoiseGit still results in an error: Logon failed, use ctrl+c to cancel basic credential prompt. As shown in Figure 2

Pushing via TortoiseGit still results in an error: Logon failed, use ctrl+c to cancel basic credential prompt.
Figure 2
Plaintext
git.exe push --progress "origin" master:master
Logon failed, use ctrl+c to cancel basic credential prompt.
Logon failed, use ctrl+c to cancel basic credential prompt.
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/shuijingwan/yii2-app-advanced.git/'


git 未能顺利结束 (退出码 128) (71079 ms @ 2021/12/17 11:26:10)


3. 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. Starting August 13, 2021, we will no longer accept account passwords when authenticating Git operations, and will require token-based authentication.

4. Configure two-factor authentication. Reference URL: https://docs.github.com/cn/authentication/securing-your-account-with-two-factor-authentication-2fa/configuring-two-factor-authentication .

5. Reference URL: https://www.jianshu.com/p/9317a927e844 . Generate a new SSH key. Open Git Bash, enter the following command, and then press Enter three times in a row: ssh-keygen -t rsa -C “shuijingwanwq@163.com”. Key save path: /c/Users/Administrator/.ssh. id_rsa is the private key, and id_rsa.pub is the public key. As shown in Figure 3

Reference URL: https://www.jianshu.com/p/9317a927e844 . Generate a new SSH key. Open Git Bash, enter the following command, and then press Enter three times in a row: ssh-keygen -t rsa -C "shuijingwanwq@163.com". Key save path: /c/Users/Administrator/.ssh. id_rsa is the private key, and id_rsa.pub is the public key.
Figure 3
Plaintext

$ ssh-keygen -t rsa -C "shuijingwanwq@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:YWBWkzDutd4GQ4/193piCd87MuJ/6HoaeAPeIi+PWRI shuijingwanwq@163.com
The key's randomart image is:
+---[RSA 2048]----+
|      *oo.       |
|     + o..       |
|      . = .      |
|     . + * .     |
|      .ES.. . .  |
|       .o++ .. . |
|       o.=o= o.o.|
|       .B.o.o==+o|
|       ooo.+B+=+o|
+----[SHA256]-----+

Administrator@LAPTOP-9S1INV5O MINGW64 ~
$


6. Add the SSH private key to ssh-agent. Start ssh-agent in the background, then add the SSH private key to ssh-agent. As shown in Figure 4

Add the SSH private key to ssh-agent. Start ssh-agent in the background, then add the SSH private key to ssh-agent.
Figure 4
Plaintext

Administrator@LAPTOP-9S1INV5O MINGW64 ~
$ eval $(ssh-agent -s)
Agent pid 2452

Administrator@LAPTOP-9S1INV5O MINGW64 ~
$ ssh-add /c/Users/Administrator/.ssh/id_rsa
Identity added: /c/Users/Administrator/.ssh/id_rsa (shuijingwanwq@163.com)


7. Add the SSH public key to your GitHub account. First, copy the entire content of the SSH public key (/c/Users/Administrator/.ssh/id_rsa.pub). As shown in Figure 5

Add the SSH public key to your GitHub account. First, copy the entire content of the SSH public key (/c/Users/Administrator/.ssh/id_rsa.pub).
Figure 5

8. To add the public key to your GitHub account, first open the GitHub SSH token management page: https://github.com/settings/keys , then add the token you just copied following the example below. As shown in Figure 6

To add the public key to your GitHub account, first open the GitHub SSH token management page: https://github.com/settings/keys , then add the token you just copied following the example below.
Figure 6

9. Test the connection. Open Git Bash and enter: ssh -T git@github.com . Running it in PowerShell still produces an error, but overall it succeeded. As shown in Figure 7

Test the connection. Open Git Bash and enter: ssh -T git@github.com . Running it in PowerShell still produces an error, but overall it succeeded.
Figure 7
Plaintext

PS E:\wwwroot\Laravel-8> ssh -T git@github.com
Warning: Permanently added the ECDSA host key for IP address '192.30.255.112' to the list of known hosts.
Hi shuijingwan! You've successfully authenticated, but GitHub does not provide shell access.

10. Test the connection. Open Git Bash and enter: ssh -T git@github.com . Running it in Git Bash succeeds.

Plaintext

Administrator@LAPTOP-9S1INV5O MINGW64 ~
$ ssh -T git@github.com
Hi shuijingwan! You've successfully authenticated, but GitHub does not provide shell access.



11. When running the command again: git push -u origin master, an error occurs: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. .

Plaintext

Administrator@LAPTOP-9S1INV5O MINGW64 /e/wwwroot/Laravel-8 (main)
$ git push -u origin main
Logon failed, use ctrl+c to cancel basic credential prompt.
Logon failed, use ctrl+c to cancel basic credential prompt.
Username for 'https://github.com': shuijingwan
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/shuijingwan/hello_laravel.git/'



12. Delete the directory: .git, then commit and push again. Error: remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. .

Plaintext

PS E:\wwwroot\Laravel-8> git branch -M main
PS E:\wwwroot\Laravel-8> git remote add origin https://github.com/shuijingwan/hello_laravel.git
PS E:\wwwroot\Laravel-8> git push -u origin main
Logon failed, use ctrl+c to cancel basic credential prompt.
Logon failed, use ctrl+c to cancel basic credential prompt.
Username for 'https://github.com': shuijingwan
Password for 'https://shuijingwan@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: Authentication failed for 'https://github.com/shuijingwan/hello_laravel.git/'

13. Open the URL: https://github.com/settings/tokens . Generate new token, and check all permissions. As shown in Figure 8

Open the URL: https://github.com/settings/tokens . Generate new token, and check all permissions.
Figure 8

14. Edit the remote URL: https://github.com/shuijingwan/hello_laravel.git , and change it to: https://xxx@github.com/shuijingwan/hello_laravel.git . Delete the directory: .git, then commit and push again. The push is successful. As shown in Figure 9

Edit the remote URL: https://github.com/shuijingwan/hello_laravel.git , and change it to: https://xxx@github.com/shuijingwan/hello_laravel.git . Delete the directory: .git, then commit and push again. The push is successful.
Figure 9
Plaintext

PS E:\wwwroot\Laravel-8> git branch -M main
PS E:\wwwroot\Laravel-8> git remote add origin https://xxx@github.com/shuijingwan/hello_laravel.git
PS E:\wwwroot\Laravel-8> git push -u origin main
Enumerating objects: 110, done.
Counting objects: 100% (110/110), done.
Delta compression using up to 4 threads
Compressing objects: 100% (91/91), done.
Writing objects: 100% (110/110), 68.51 KiB | 1.16 MiB/s, done.
Total 110 (delta 7), reused 0 (delta 0)
remote: Resolving deltas: 100% (7/7), done.
To https://github.com/shuijingwan/hello_laravel.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
PS E:\wwwroot\Laravel-8>Git Bash

15. View the Git repository on GitHub to confirm that the files have been successfully pushed to GitHub. As shown in Figure 10

View the Git repository on GitHub to confirm that the files have been successfully pushed to GitHub.
Figure 10

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系