启用2FA后,Git认证失败

我只启用了2FA(我想不出任何其他更改),并且git询问我的用户名和密码。 我提供了两个,但他们是“错误的”。 我在这里尝试了许多解决方案:Git推送需要用户名和密码,但这并不起作用。 特别是,当从https切换到ssh时,ssh密钥给出

权限被拒绝(publickey)。 致命:无法从远程存储库读取。

$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Username for 'https://github.com': **********
Password for 'https://mlbileschi@github.com': 
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/mlbileschi/scala.git/'

有小费吗?


您需要生成访问令牌。 您可以通过转到设置页面来创建一个。

在这里输入图像描述

在命令行中使用此访问令牌作为您的密码。


端到端解决方案需要3个步骤。

  • 荣誉Gergo Erdosi。 他的回答基本上是正确的,只是Github改变了这个设置页面。 截至2016年末,您需要从您的个人访问令牌页面生成访问令牌

    在这里输入图像描述

    在命令行中使用此访问令牌作为您的密码。

  • 您可以通过将其包含到您的项目远程URL中来保存您的用户名。 要做到这一点的一种方法是编辑你的.git/config ,将url行修改为以下格式:

    url = https://YOUR_USERNAME_HERE@github.com/owner/repo.git

  • 只能通过运行一次来​​保存密码:

    $ git config credential.helper store

    然后您的未来git密码将以明文形式存储在〜/ .git-credentials中,格式为https://user:PlaintextPassword@example.com

    以明文存储密码通常会被视为安全风险。 但在这种2FA情况下,凭证不是您的真实密码,而是随机生成的字符串。 所以它与使用ssh私钥和无密码ssh私钥一样安全。 CAVEAT:请记住,如果您碰巧也在本机上使用另一个没有2FA的git帐户,那么这些真实密码也将以明文形式存储。

  • PS:或者,您可以选择使用基于ssh的登录,使用密码保护的ssh私钥,这会更安全,不太方便,但这不在此答案的范围内。


    我有类似的问题。 我不得不改变git命令中使用的URL来包含我的用户名。

    git push https://YOUR_USERNAME_HERE@github.com/mlbileschi/scala.git
    

    然后,当它要求PW使用您根据Gergo Erdosi的回答中的说明创建的访问令牌时。

    链接地址: http://www.djcxy.com/p/92215.html

    上一篇: Git authentication fails after enabling 2FA

    下一篇: Authenticate with GitHub using token