Git
简体中文 ▾ Topics ▾ Latest version ▾ git-credential-store last updated in 2.44.0

名称

git-credential-store - 在磁盘上存储凭证的助手

概述

git config credential.helper 'store [<选项>]'

描述

Note
使用这个助手会将你的密码未加密地存储在磁盘上,只受文件系统权限的保护。如果这不是一个可接受的安全权衡,请尝试 git-credential-cache[1],或者找一个能与你的操作系统提供的安全存储整合的助手。

该命令在磁盘上无限期地存储凭证,供未来的 Git 程序使用。

你可能不想直接调用这个命令;它是作为 git 其他部分的凭证助手来使用的。参见 gitcredentials[7] 或下面的 EXAMPLES

选项

--file=<路径>

使用 <路径> 来查询和存储证书。该文件将设置其文件系统权限,以防止系统中的其他用户读取它,但不会被加密或其他保护。如果没有指定,将从 ~/.git-credentials$XDG_CONFIG_HOME/git/credentials 中搜索证书,如果证书存在,将被写入 ~/.git-credentials,如果证书存在而前者不存在,则写入 $XDG_CONFIG_HOME/git/credentials。参见 文件

文件

如果没有用 --file 明确设置,有两个文件,git-credential-store 将按照优先顺序搜索证书:

~/.git-credentials

用户特定的凭证文件。

$XDG_CONFIG_HOME/git/credentials

第二个用户专用的证书文件。如果 $XDG_CONFIG_HOME 没有设置或为空,$HOME/.config/git/credentials 将被使用。如果 ~/.git-credentials 也有匹配的凭证,那么存储在该文件中的任何凭证将不会被使用。如果你有时使用不支持该文件的旧版本的 Git,那么不创建该文件是个好主意。

对于凭证查询,文件按上述顺序读取,发现的第一个匹配凭证优先于在列表后面的文件中发现的凭证。

凭证存储将默认写到列表中的第一个现有文件。如果这些文件都不存在,~/.git-credentials 将被创建并写入。

擦除证书时,匹配的证书将从所有文件中擦除。

实例

这个助手的意义在于减少你必须输入用户名或密码的次数。比如说:

$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <输入您的用户名>
Password: <输入密码>

[几天后]
$ git push http://example.com/repo.git
[自动使用您的证书]

存储格式

.git-credentials 文件是以明文存储的。每个凭证都以 URL 的形式存储在自己的一行中,比如:

https://user:pass@example.com

文件中不允许有其他类型的行(如空行或注释行),尽管有些行可能被默默地忽略了。不要用编辑器查看或编辑该文件。

When Git needs authentication for a particular URL context, credential-store will consider that context a pattern to match against each entry in the credentials file. If the protocol, hostname, and username (if we already have one) match, then the password is returned to Git. See the discussion of configuration in gitcredentials[7] for more information.

GIT

属于 git[1] 文档

scroll-to-top