【问题标题】:Update command-line Git credential.helper for Personal Access Tokens (PAT) on GitHub更新 GitHub 上个人访问令牌 (PAT) 的命令行 Git credential.helper
【发布时间】:2021-10-19 18:56:57
【问题描述】:

我有几个存储库,显然我在使用缓存版本的 GitHub 密码身份验证。我最近才知道这一点,因为 GitHub 不再支持密码,而是需要个人访问令牌 (PAT) 或 SSH 密钥。

我会在拉取或推送时收到所有私有存储库的以下消息:

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: unable to access 'https://github.com/villano-lab/CEvNS.git/': The requested URL returned error: 403

我通过查看this 帖子解决了这个问题。根据该信息,我推断我应该检查我的参数credential.helper。通过这样做:

git config --list

我发现它被设置为这样的“存储”:

credential.helper=store

所以我所做的就是这样设置:

git config credential.helper ""

这样做是允许我再次输入我的用户名和密码(而不是由 git 客户端以默认方式提供)。然后我能够create a GitHub Personal Access Token 并在密码字段中使用它,并且满足了新的 GitHub 要求并且我没有收到错误。

问题是,我怎样才能让它永久化?比如,我如何将 PAT 放入 git 客户端缓存中,这样我就不必像以前那样再次输入它了?截至目前,如果我回到:

git config credential.helper store

它会回到旧密码,GitHub 会拒绝它。

【问题讨论】:

  • 当您选择存储时,它会存储在您的操作系统凭据管理器中。所以你必须找到它的存储位置并删除存储的 Github 凭据,以便 git 再次询问你密码。
  • @Philippe 谢谢。知道如何找到在哪里吗? stackoverflow.com/questions/35942754/… 建议 ~/.git-credentials;但它不存在。

标签: git github


【解决方案1】:

您应该将您的凭证助手设置回原来的状态:git config --global credential.helper store。然后,使用technique outlined in the Git FAQ 重置您的凭证助手中的凭证:

$ echo url=https://account@github.com | git credential reject

您应该将 account 替换为您的 GitHub 用户名。

然后,下一次,Git 会提示你输入凭据,你应该输入你的 GitHub 用户名作为用户名,输入你的个人访问令牌作为密码。然后凭据助手将保存它们。

【讨论】:

  • 很好的答案。注意:在我的一个本地存储库中,出于某种原因,credential.helper 变量显式设置为其他值(空白)。所以我不得不做git config --unset-all credential.helper 以确保没有本地设置覆盖全局设置(我认为?)。
【解决方案2】:

在 OSX 上,您似乎也可以将osxkeychain 用于credential.helper。我首先通过取消设置任何全局值来测试这一点:

git config --global --unset credential.helper

然后,我继续删除现有的 github.com 钥匙串,该钥匙串已经在 osxkeychain 中,方法是从 finder 进入实用程序并选择钥匙串应用程序:

搜索“git”后清楚地显示了git的各种键:

我从这个管理器中删除了 github.com 密钥。

然后我设置了允许使用osxkeychain 的本地设置。我认为您也可以将其设为全局,但我只是在一个存储库上对其进行了测试。

git config credential.helper osxkeychain

然后我尝试了git pull,并被要求提供我的github.com 凭据,此时我提供了我的 PAT。然后将其保存在github.com 密钥中并在以后使用。

据推测,我可以将其设置为全局以在所有存储库中使用此链,例如:

git config --unset credential.helper

git config --global credential.helper osxkeychain

我相信osxkeychain 的好处是不在您的系统上存储纯文本密码文件。与上面的 store 方法相反。

【讨论】:

    猜你喜欢
    • 2019-08-24
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2021-12-12
    • 2022-01-22
    • 2021-09-04
    • 1970-01-01
    • 2022-11-22
    相关资源
    最近更新 更多