Linux - Git 凭据 - 如何删除用户名/密码组合的实例?

8

我刚刚安装了Libsecret,并将其指向存储我的git凭证的位置:

git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret

但我真的不理解如何使用它......就是完全不懂。

使用它一直是一个相当黯淡的经历,实际上在Linux上似乎是目前唯一好的解决方案(距今仅有2年最后更新,而其他选项则是3年或更长时间)。

是否有一种方法可以撤销存储在Libsecret上的用户名/密码?例如,我没有任何办法来清除它,除了进行--unset credential.helper,这只会清除所有内容。 我不能通过与存储密码相关的库/链接来缩小范围吗? Windows上的凭证管理器通过UI使得这个过程非常简单明了。

抱歉抱怨并谈论Windows的等效功能,但有人可以解释一下吗?

如果有更好的替代方案,请随意不要使用Libsecret。 请提供任何建议,将不胜感激

3个回答

9
完全不清楚如何做,而libsecret文档 - https://developer.gnome.org/libsecret/0.18/ - 只是API/库文档。如果您正在为libsecret编程接口,则非常好。但如果您是终端用户并想要更新或删除条目,则不太好。

另外,我发现取消设置git全局配置条目credential.helper只会将git恢复到使用未缓存的凭据。但当我将该设置指回git-credential-libsecret时,我的旧密码仍然被保存了。

因此,删除或更新单个条目的答案其实相对简单。但并不明显。

  1. 如果还没有安装Seahorse (https://wiki.gnome.org/Apps/Seahorse),请先安装。它会在应用程序菜单中显示为“密码和密钥”

  2. 运行Seahorse

    • 登录(密钥链)-> https://@github.com | 网络密码
  3. 双击或右键单击以编辑、复制或删除


确实,这是唯一对我有效的解决方案。(Ubuntu 20.04,git版本2.25.1) - Boson Bear
这是我唯一可行的解决方案!(同样适用于Ubuntu 20.04) - paultop6

4
正如其他答案中提到的,Seahorse 是一个图形界面前端,用于访问相同的密钥环,但也有一个称为 secret-tool 的命令行界面前端,可以访问相同的内容。
不需要摆弄 git 凭证助手后面的东西。
任何 git 凭证助手都支持“擦除”方法,例如在 contrib/credential/libsecret/git-credential-libsecret.c 的源代码中所示。
/*
 * Table with helper operation callbacks, used by generic
 * credential helper main function.
 */
static struct credential_operation const credential_helper_ops[] = {
    { "get",   keyring_get },
    { "store", keyring_store },
    { "erase", keyring_erase },
    CREDENTIAL_OP_END
};

因此,要删除凭据条目,您需要键入:

printf "protocol=https\nhost=github.com\nusername=<me>" | \
  git-credential-libsecret erase

将“github.com”和<me> 替换为实际的远程站点和远程帐户用户名。

如果您的凭据助手不是libsecret,而是“manager-core”(使用跨平台的Microsoft GCM),则应该是:

printf "protocol=https\nhost=github.com\nusername=<me>" | \
  git-credential-manager-core erase

如果您的凭证助手不是libsecret,而是其他助手,如"store"、"cache"等:

printf "protocol=https\nhost=github.com\nusername=<me>" | \
  git-credential-xxx erase

只需输入你的凭证辅助命令: 它就会显示其命令。
在我的情况下:

git-credential-manager-core
Required command was not provided.

Usage:
  git-credential-manager-core [options] [command]

Options:
  --version         Show version information
  -?, -h, --help    Show help and usage information

Commands:
  get            [Git] Return a stored credential
  store          [Git] Store a credential
  erase          [Git] Erase a stored credential
  configure      Configure Git Credential Manager as the Git credential helper
  unconfigure    Unconfigure Git Credential Manager as the Git credential helper
  azure-repos    Commands for interacting with the Azure Repos host provider

请确保它在您的$PATH中(如果不在:/usr/lib/git-core,则应该在/usr/bin)

旧版本的帮助程序可能无法显示所有“操作”命令,并使用erase的旧同义词(removedelete

要检查erase/remove/delete是否起作用,请先显示您存储的密码("get"),然后执行"erase",然后尝试再次显示它,再次使用"get"操作:

printf "protocol=https\nhost=github.com\nusername=<me>" | \
  git-credential-xxx get

如果提示您输入用户名/密码,则表示您已成功删除缓存条目。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接