简体   繁体   English

将SSH密钥添加到Github后,为什么不能继续使用https对git进行身份验证?

[英]Why can I not keep authenticating git with https after having added SSH key to Github?

  • In the past, I've cloned repos with https authentication. 过去,我使用https身份验证克隆了回购协议。
  • Recently, I started using SSH authentication. 最近,我开始使用SSH身份验证。
  • When setting up SSH with Github, I also changed my main Github password. 使用Github设置SSH时,我还更改了我的主要Github密码。

Whenever I enter some old cloned repository on my local drive, which is still using https, I'm no longer allowed to eg git push: 每当我在仍使用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/'
  • The .git/config is untouched from back when the repository was cloned using https, so the url in this file is set to https://github.com ... 当使用https克隆存储库时, .git/config不会被修改,因此该文件中的url设置为https://github.com ...
  • I'm entering my NEW password. 我正在输入新密码。

I could now change the url in .git/config to use the SSH keys: url = git@github... . 我现在可以将.git/config的url更改为使用SSH密钥: url = git@github... But I'd like to keep using https here. 但我想在这里继续使用https。 How can I do that? 我怎样才能做到这一点?

SSH key is for SSH connection and not HTTP(S). SSH密钥用于SSH连接,而不用于HTTP(S)。

If your repository already has a remote repository setup with HTTP, you can easily change it with the command git remote set-url origin git@github.com:USER/REPO.git 如果您的存储库已经具有使用HTTP的远程存储库设置,则可以使用命令git remote set-url origin git@github.com:USER/REPO.git轻松更改它。

Turns out this didn't have anything to do with SSH keys being added. 原来,这与添加的SSH密钥没有任何关系。 I also added two-factor authentication (2FA) which was the reason I started having issues. 我还添加了两因素身份验证(2FA),这就是我开始遇到问题的原因。

The solution is to create a token and use that instead of the password when managing a repository via HTTPS: https://help.github.com/articles/https-cloning-errors#provide-access-token-if-2fa-enabled 解决方案是创建一个令牌,并在通过HTTPS管理存储库时使用该令牌代替密码: https : //help.github.com/articles/https-cloning-errors#provide-access-token-if-2fa-enabled

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM