推送到GitHub上的仓库时,身份验证失败从GitHub桌面和命令行

问题描述

  • 我正在Windows 10 64bit上使用GitHub Desktop v2.5.7和Git v2.29.1。
  • 我的GitHub帐户已启用2FA。
  • 我可以使用GitHub Desktop或命令行从GitHub克隆存储库
  • 我已生成一个SSL密钥,并按照所有说明将其添加到本地和GitHub
  • 我已经生成一个个人访问令牌,并尝试在命令行中使用它,还有我的密码

问题:当我尝试将更改推送到存储库时,出现身份验证错误

GitHub桌面中的错误

screenshot of error - authentication failed. Some common reasons include...

命令行错误

打开sslverify:

fatal: unable to access 'https://github.com/jacquibo/neo4jDataSets.git/': SSL certificate problem: unable to get local issuer certificate

关闭sslverify:

info: please complete authentication in your browser...
fatal: incorrect_client_credentials: The client_id and/or client_secret passed are incorrect. [https://docs.github.com/apps/managing-oauth-apps/troubleshooting-oauth-app-access-token-request-errors/#incorrect-client-credentials]
Username for 'https://github.com': [email protected]
Password for 'https://[email protected]@github.com':
remote: No anonymous write access.
fatal: Authentication Failed for 'https://github.com/myusername/myrepo.git/'

我尝试过:

  • GitHub中错误的所有建议
  • 在本地和GitHub上添加ssh密钥(当我使用ssh -i mycertname -vT [email protected]时,会收到权限被拒绝的消息,请参见下文)
  • 添加个人访问令牌
  • 检查来源为https

使用命令行测试SSL证书时出错:

OpenSSH_8.4p1,OpenSSL 1.1.1h  22 Sep 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [140.82.121.4] port 22.
debug1: connect to address 140.82.121.4 port 22: Permission denied
ssh: connect to host github.com port 22: Permission denied

如果还有其他想法,我将不胜感激。实际上只能在GitHub.com上编辑文件不是很实际。谢谢。

解决方法

您需要使用ssh来访问存储库,而不是HTTP。

将遥控器的URL从https://xxx更改为git://xxx

您可以使用GitHub存储库代码页右侧的绿色按钮来帮助您获取正确的URL。更改自:

HTTPS URL

SSH URL

您需要做的另一件事是确保您具有git的最新本地安装。如果您安装了旧版本的git,则可能会遇到错误。

,

这是因为您的 github 帐户中没有 SSH 密钥。 按照文档将 SSH 密钥安装到您的 github 帐户。

https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent