1、在执行命令时: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.。如图1
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、通过 TortoiseGit 推送,仍然报错:Logon failed, use ctrl+c to cancel basic credential prompt.。如图2
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、远程:2021 年 8 月 13 日移除了对密码身份验证的支持。请改用个人访问令牌。远程:请参阅 https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ 了解更多信息。从 2021 年 8 月 13 日开始,我们将在对 Git 操作进行身份验证时不再接受帐户密码,并将要求使用基于令牌的身份验证。
4、配置两步验证,参考网址:https://docs.github.com/cn/authentication/securing-your-account-with-two-factor-authentication-2fa/configuring-two-factor-authentication 。
5、参考网址:https://www.jianshu.com/p/9317a927e844 。生成一个新的 SSH 密钥。打开 Git Bash,输入如下命令,然后连续按三个回车即可:ssh-keygen -t rsa -C “shuijingwanwq@163.com”。密钥保存路径:/c/Users/Administrator/.ssh。id_rsa 是密钥,id_rsa.pub 是公钥。如图3
$ 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、将 SSH 私钥添加到 ssh-agent,在后台启动 ssh-agent,将 SSH 私钥添加到 ssh-agent。如图4
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、将 SSH 公钥添加到 GitHub 账户,先复制 SSH 公钥的完整内容(/c/Users/Administrator/.ssh/id_rsa.pub)。如图5
8、将公钥添加到 GitHub 账号,先打开 Github SSH 令牌管理页面:https://github.com/settings/keys ,然后把你刚刚复制的令牌按照下图示例添加。如图6
9、测试连接,打开 Git Bash 输入:ssh -T git@github.com 。在 PowerShell 中执行仍然报错,但是总体是成功了。如图7
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、测试连接,打开 Git Bash 输入:ssh -T git@github.com 。但是在 Git Bash 中执行成功。
Administrator@LAPTOP-9S1INV5O MINGW64 ~ $ ssh -T git@github.com Hi shuijingwan! You've successfully authenticated, but GitHub does not provide shell access.
11、再次执行命令时:git push -u origin master,报错:Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.。
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、删除目录:.git,重新提交与推送。报错:remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.。
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、打开网址:https://github.com/settings/tokens 。Generate new token,勾选所有权限。如图8
14、编辑远端 URL:https://github.com/shuijingwan/hello_laravel.git ,修改为:https://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@github.com/shuijingwan/hello_laravel.git 。删除目录:.git,重新提交与推送。推送成功。如图9
PS E:/wwwroot/Laravel-8> git branch -M main PS E:/wwwroot/Laravel-8> git remote add origin https://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@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、查看 GitHub 上的 Git 仓库,确认文件已经成功推送至 GitHub。如图10
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/251078.html