如何使用git与gnome-keyring集成

时间:2012-11-14 19:15:05

标签: git gnome

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)

9 个答案:

答案 0 :(得分:180)

@ 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

答案 1 :(得分:52)

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命令应该指向可执行文件。这就是为什么它不适合我。

答案 2 :(得分:24)

2016年第4季度更新:

  • Unix,Mac(Git 2.11 +)

    git config --global credential.helper libsecret
    

(参见“Error when using Git credential helper with gnome-keyring”)

  • 视窗:

    git config --global credential.helper manager
    

(请参阅“How to sign out in Git Bash console in Windows?”: Git for Windows 使用最新的Microsoft Git Credential Manager for Windows


原始答案(2012)

适用于Windows,Mac和Unix平台的Credential Helpers首先在"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使用它。

您使用的是“凭据帮助程序”(反过来,它将调用any credential API it wants on Windows)。

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

答案 3 :(得分:11)

对于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

答案 4 :(得分:8)

更新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

答案 5 :(得分:6)

只需将这两行添加到~/.gitconfig文件中:

[credential]
    helper = gnome-keyring

下次Git要求您输入密码时,输入的密码将保存到Gnome Keyring(您可以使用seahorse工具查看),并且不会再次要求您输入密码之后。

这假设您的Git版本足够新(如2.1.0)并且您在 Linux Fedora,RHEL或CentOS下。对于旧版本或其他操作系统/发行版,请查看其他答案。

答案 6 :(得分:1)

在Fedora上,您需要安装

$ sudo dnf install git-credential-libsecret

并编辑您的 git配置以使用凭据帮助器。

[credential]
    helper = /usr/libexec/git-core/git-credential-libsecret

仅供参考,libsecret软件包最近被拆分了,请参见post from @rugk。这就是用户需要重新安装此软件包的原因。

答案 7 :(得分:0)

某些发行版的确集成了此集成,而无需任何编译。根据您的GNOME版本,您需要安装gnome-keyringlibsecret版本的软件包,例如git-credential-gnome-keyring(OpenSUSE Leap 42.3)。

但是,它本身不会自动启用Git与GNOME密钥环的集成。您仍然必须配置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

答案 8 :(得分:0)

我在无头服务器上尝试了 the answer for 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):

  • 首先,我运行与 the answer 中相同的命令,将 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 之类的自动身份验证。