Py学习  »  Git

更新命令行Git凭据。GitHub上个人访问令牌(PAT)的助手

villaa • 3 年前 • 1368 次点击  

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

对于所有pull或push上的私有存储库,我会得到以下消息:

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将拒绝它。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129655
 
1368 次点击  
文章 [ 2 ]  |  最新文章 3 年前
villaa
Reply   •   1 楼
villaa    3 年前

在OSX上,您似乎也可以使用 osxkeychain 对于 credential.helper .我首先通过不确定任何全球价值来检验这一点:

git config --global --unset credential.helper

然后,我继续删除了现有的 github.com 钥匙链已经在 osxkeychain 通过从finder进入实用程序并选择Keychain应用程序:

keychain application

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

github.com key

我删除了github。此管理器中的com密钥。

然后我设置了一个本地设置,允许使用 osxkeychain .我想你也可以将其全球化,但我只是在一个存储库上进行了测试。

git config credential.helper osxkeychain

然后我试着 git pull 我被要求提供我的 github。通用域名格式 在那一点上,我提供了我的个人资料。然后,它被保存在 github。通用域名格式 钥匙,后来用过了。

想必,我可以在全球范围内设置它,以便在所有存储库中使用此链,例如:

git config --unset credential.helper

git config --global credential.helper osxkeychain

我相信 osxkeychain 具有不在系统中存储纯文本密码文件的优点。而不是 store 方法,上面的方法可以。

bk2204
Reply   •   2 楼
bk2204    3 年前

您应该将凭证助手设置回原来的状态: 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用户名作为用户名,输入个人访问令牌作为密码。凭证助手随后将保存它们。