http://www.h-online.com/open/news/item/Git-1-8-0-can-access-Windows-and-GNOME-keyrings-1733879.html
在阅读有关Git凭据助手的文档http://git-scm.com/docs/gitcredentials.html之后,我无法找到使用此新功能的方法。 我该如何集成它?我正在使用从Archlinux存储库安装的Archlinux(git 1.8.0)。http://www.h-online.com/open/news/item/Git-1-8-0-can-access-Windows-and-GNOME-keyrings-1733879.html
在阅读有关Git凭据助手的文档http://git-scm.com/docs/gitcredentials.html之后,我无法找到使用此新功能的方法。 我该如何集成它?我正在使用从Archlinux存储库安装的Archlinux(git 1.8.0)。@marcosdsanchez的回答适用于Arch Linux(回答了原始问题),但我使用Ubuntu。对于git>= 2.11:
sudo apt-get install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
对于 git < 2.11:
sudo apt-get install libgnome-keyring-dev
cd /usr/share/doc/git/contrib/credential/gnome-keyring
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
Git 1.8.0带有gnome-keyring支持,但二进制文件需要针对您的平台进行编译。
这是我在Archlinux上解决它的方法:
$ sudo pacman -S libgnome-keyring
$ cd /usr/share/git/credential/gnome-keyring
$ make
$ git config --global credential.helper /usr/share/git/credential/gnome-keyring/git-credential-gnome-keyring
@VonC的解决方案接近了,但是git config命令应该指向可执行文件。这就是为什么它对我不起作用的原因。
apt-get install libgnome-keyring-dev
安装这些库。此外,我还需要从https://github.com/git/git/tree/master/contrib手动下载git contrib repo并将其放置在/usr/share/git-core/中。这些文件不再包含在默认的Git安装中,至少在使用官方Git-Core Ubuntu PPA时是如此。 - Johanngit-credential-gnomekeyring
已经不存在了,遗憾的是在AUR中没有这样的信息。 - ryenus/usr/share/
目录下没有git文件夹...只有gitweb和git-core。但是我使用的是Git 1.7.9版本。这可能是原因吗...? - temporary_user_namelibgnome-keyring
即可(至少如果您正在使用gnome)。 - ald.lilibgnome-keyring
现已被弃用,需要安装org.freedesktop.secrets
包之一。其中新的gnome-keyring
是其一。 - Peilonrayz2016年第四季度更新:
Unix,Mac(Git 2.11+)
git config --global credential.helper libsecret
gnome-keyring
错误”)
Windows:
git config --global credential.helper manager
(参见“如何在Windows的Git Bash控制台中注销?”:这是使用最新的Git for Windows和Microsoft Git Credential Manager for Windows)
提醒: libgnome-keyring
是特定于GNOME的,并且:
原始答案(2012年)
凭证助手已经在Windows、Mac和Unix平台上推出,最初是在"git-credential-helper" repo中引入的,现在已经包含在git发行版中:
该存储库包含一组Git凭证助手(
gitcredentials
(7)),它们是git
的一部分(或者将来可能被贡献)。
$ git clone git://github.com/pah/git-credential-helper.git
$ BACKEND=gnome-keyring # or any other backend
$ cd git-credential-helper/$BACKEND
$ make
$ cp git-credential-$BACKEND /path/to/git/crendential
构建完成后,它将被安装在/path/to/git/credential
目录中。
要使用此后端,您可以通过设置以下方式将其添加到您的(全局)Git配置中
(这里是Unix):
git config --global credential.helper /path/to/git/credential/gnome-keyring/git-credential-gnome-keyring
Windows 注意事项:
我想你可以在 Windows 上运行一个程序,并调用类似 "pypi keyring 0.10" 的库。
但那是后端,你不能直接从 Git 中使用它。
你正在使用的是一个“凭证助手”(它将调用 Windows 上任何凭证 API)。
GitHub for Windows 提供了这样一个助手(作为一个名为... github
的可执行文件),并且可以在 Windows 会话期间存储你的凭证。
从“GitHub for Windows”窗口启动一个 shell,然后输入“git config --system -l
”,你会看到:
C:\Users\VonC\Documents\GitHub\test [master +2 ~0 -0 !]> git config --system -l
credential.helper=!github --credentials
credential.helper=!github --credentials
部分将调用凭证助手 'github
'。
$ git config [--global] credential.helper $BACKEND
2018年10月更新
GNOME已经弃用libgnome-keyring并用libsecret替代。提交https://github.com/git/git/commit/87d1353a6a 添加了一个新的凭证助手/usr/libexec/git-core/git-credential-libsecret。
git config --global credential.helper libsecret
对于使用 Fedora 的任何人,我稍微编辑了 James Ward 的答案:
sudo yum install libgnome-keyring-devel
cd /usr/share/doc/git/contrib/credential/gnome-keyring
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
/usr/libexec/git-core/git-credential-gnome-keyring
。 - slmgit config --global credential.helper gnome-keyring
。 - RedPoppysudo dnf install git-credential-libsecret
然后 git config --global credential.helper libsecret
- vk5tu只需在您的~/.gitconfig
文件中加入以下两行:
[credential]
helper = gnome-keyring
seahorse
工具查看),之后你就不会再被要求输入密码了。git: 'credential-gnome-keyring'不是一个git命令。
- Ferit在 Fedora 上,您需要安装
$ sudo dnf install git-credential-libsecret
并且编辑您的git配置文件以使用凭证助手。
[credential]
helper = /usr/libexec/git-core/git-credential-libsecret
提醒一下,libsecret
软件包最近被拆分了,详情请见@rugk的帖子。这就是为什么用户需要重新安装此软件包的原因。
我试图在一个无头服务器上尝试Ubuntu的解答,当我输入我的令牌时,出现了以下错误:
Remote error from secret service: org.freedesktop.DBus.Error.UnknownMethod: No such interface 'org.freedesktop.Secret.Collection' on object at path /org/freedesktop/secrets/collection/login
store failed: No such interface 'org.freedesktop.Secret.Collection' on object at path /org/freedesktop/secrets/collection/login
这是在无头服务器上为我解决问题的方法(请参见https://keyring.readthedocs.io/en/latest/#using-keyring-on-headless-linux-systems):
git-credential-libsecret
设置为credential.helper
:# You may also first install gnome-keyring if not installed
sudo apt install gnome-keyring
sudo apt install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
git push
这样的命令),我都会运行以下命令:dbus-run-session -- sh # Replace 'sh' with whatever shell you use.
gnome-keyring-daemon --unlock
# Enter your token here, then hit Enter, then Ctrl+d
# You might clean the terminal display with Ctrl+l for security reasons
这将在D-Bus会话中运行,使我可以自动验证身份,并执行一些命令,例如git push
等。
有些发行版会作为安装包提供此集成功能,无需进行编译。根据您的 GNOME 版本,您需要安装软件包的 gnome-keyring
或 libsecret
版本,在 OpenSUSE Leap 42.3 中类似于 git-credential-gnome-keyring
。
然而,这本身并不会自动启用 Git 与 GNOME Keyring 的集成。您仍然需要配置 Git 使用此凭证存储方法:
git config --global credential.helper gnome-keyring # If you installed git-credential-gnome-keyring
git config --global credential.helper libsecret # If you installed git-credential-libsecret
libsecret
(或者find /usr -iname git-credential-libsecret
的结果)是在Gentoo Linux中的正确选项。请注意,必须使用USE=gnome-keyring
来安装dev-vcs/git
。 - sphakkaArch Linux的git软件包包括git-credential-libsecret(替代了git-credential-gnome-keyring),因此您可以运行:
git config --global credential.helper libsecret
除了输入密码或个人令牌之外,您还可以尝试git-credential-oauth。
不再需要密码!不再需要个人访问令牌!不再需要SSH密钥!
Git凭据助手使用OAuth安全地验证到GitHub、GitLab、BitBucket和其他锻造厂。
第一次推送时,助手将打开一个浏览器窗口进行身份验证。存储生命周期内的后续推送不需要任何交互。
这与任何存储助手兼容,包括git-credential-cache或git-credential-libsecret。
git help -a | grep credential-
命令查看是否安装了其他帮助程序。默认情况下会有两个:credential-cache
(在输入密码后记住密码一段时间,默认为15分钟) 和credential-store
(将密码明文存储在未加密的磁盘文件中, 默认路径为~/.git-credentials
)。 - ShreevatsaRchmod 0755 git-credential-gnome-keyring
,以添加除 root 用户外的其他用户执行权限。 - Lari Hotari