在为Github添加SSH密钥后,为什么我不能继续使用https验证git?

时间:2016-07-05 11:09:06

标签: git github ssh

  • 过去,我使用 https 身份验证克隆了回购。
  • 最近,我开始使用 SSH 身份验证。
  • 使用Github设置SSH时,我也更改了主要的Github密码。

每当我在仍在使用https的本地驱动器上输入一些旧的克隆存储库时,我不再允许例如git push:

Username for 'https://github.com': MYUSERNAME
Password for 'https://MYUSERNAME@github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/USER/REPO.git/'
  • 使用https克隆存储库时,.git/config从后面不受影响,因此此文件中的url设置为https://github.com ...
  • 我输入了我的新密码。

我现在可以更改.git/config中的网址以使用SSH密钥:url = git@github...。但是我想在这里继续使用https。我怎么能这样做?

2 个答案:

答案 0 :(得分:0)

SSH密钥用于SSH连接,而不是HTTP(S)。

如果您的存储库已经使用HTTP设置了远程存储库,您可以使用命令git remote set-url origin git@github.com:USER/REPO.git

轻松更改它

答案 1 :(得分:0)

事实证明,这与添加的SSH密钥没有任何关系。我还添加了双因素身份验证(2FA),这也是我开始遇到问题的原因。

解决方案是创建一个令牌,并在通过HTTPS管理存储库时使用该令牌而不是密码:https://help.github.com/articles/https-cloning-errors#provide-access-token-if-2fa-enabled