如何使用git与gnome keyring集成



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,git是从Archlinux的存储库中安装的。(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

Git1.8.0支持gnome密钥环,但需要为您的平台编译二进制文件。

这就是我在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年第4季度更新:

  • Unix、Mac(Git 2.11+)

    git config --global credential.helper libsecret
    

(参见"使用gnome-keyring的Git凭证助手时出错")

  • Windows:

    git config --global credential.helper manager
    

(请参阅"如何在Windows中的Git Bash控制台中注销?":即Git for Windows使用最新的Microsoft Git凭据管理器)

提醒:libgnome-keyring特定于GNOME,并且是:

  • 自2014年1月起弃用
  • Git 2.41完全删除(2023年第二季度)

原始答案(2012)

用于Windows、Mac和Unix平台的凭证帮助程序已在";git凭证助手";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钥匙圈0.10〃
但这是后端,您不能直接从Git使用它。

你正在使用的是一个";凭证助手";(反过来,它将调用它在Windows上想要的任何凭据API)。

GitHub for Windows提供了这样一个助手(作为一个名为…github的可执行文件),可以在Windows会话期间存储您的凭据
从该"shell"启动shell;GitHub for Windows";windows,你会看到,键入";git config --system -l":

C:UsersVonCDocumentsGitHubtest [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密钥环,并将其替换为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

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

[credential]
helper = gnome-keyring

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

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

在Fedora上,您需要安装

$ sudo dnf install git-credential-libsecret

并编辑git配置以使用凭据助手。

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

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

一些发行版确实将此集成作为安装包提供,而不需要任何编译。根据您的GNOME版本,您需要安装gnome-keyringlibsecret版本的软件包,类似于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-无头linux系统上的keyring):

  • 首先,我运行与答案中相同的命令,将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会话,在该会话中,I可以运行例如git push等具有自动身份验证的会话。

Arch Linux的git包包括git credential libsecret(它取代了git creential gnome keyring),因此您可以运行:

git config --global credential.helper libsecret

作为输入密码或个人令牌的替代方案,您也可以尝试git凭据oauth。

不再有密码!不再有个人访问令牌!没有更多的SSH密钥

一个Git凭据助手,使用OAuth安全地对GitHub、GitLab、BitBucket和其他伪造文件进行身份验证。

第一次推送时,助手将打开浏览器窗口进行身份验证。存储寿命内的后续推送不需要交互。

这与任何存储助手兼容,包括git凭据缓存或git凭据libsecret。

最新更新