Git 1.8.0 支持与 gnome-keyring 的集成。
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。 (git 1.8.0)
@marcosdsanchez 的回答是针对 Arch(它回答了最初的问题),但我在 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 命令应该指向可执行文件。这就是为什么它对我不起作用。
2016 年第四季度更新:
Unix、Mac(Git 2.11+)
git config --global credential.helper libsecret
(请参阅“使用 Git 凭据助手时出错
gnome-keyring
”)
窗户:
git config --global credential.helper manager
(参见“如何在 Windows 中退出 Git Bash 控制台?”:即Git for Windows 使用最新的Microsoft Git Credential Manager for Windows)
温馨提示:
libgnome-keyring
是GNOME特有的,是:
Credential Helpers,适用于 Windows、Mac 和 Unix 平台,首先在
"git-credential-helper" repo 中引入,现在已经包含在 git distro 中:
此存储库包含一组 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 上运行的程序并调用像“
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
GNOME 已弃用 libgnome-keyring 并将其替换为 libsecret。提交
https://github.com/git/git/commit/87d1353a6a添加了一个新的凭证助手/usr/libexec/git-core/git-credential-libsecret。
git config --global credential.helper libsecret
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
~/.gitconfig
文件中:
[credential]
helper = gnome-keyring
下次 Git 要求你输入密码时,输入的密码将保存到 Gnome Keyring(你可以用
seahorse
工具看到),之后就不会再要求你输入密码了。这假设您的 Git 版本足够新(例如 2.1.0)并且您使用的是
Linux Fedora、RHEL 或 CentOS。对于旧版本或其他操作系统/发行版,请查看其他答案。
install
$ sudo dnf install git-credential-libsecret
并编辑您的
git 配置 以使用凭证助手。
[credential]
helper = /usr/libexec/git-core/git-credential-libsecret
仅供参考,
libsecret
包最近被拆分,请参阅@rugk的post。这就是为什么用户需要重新安装这个包。
gnome-keyring
或
libsecret
版本的软件包,例如
git-credential-gnome-keyring
(OpenSUSE Leap 42.3)。但是,这本身并不会自动启用 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
无头服务器上尝试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
和类似的自动身份验证。