如何使用git与gnome-keyring集成

mar*_*hez 122 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)

Jam*_*ard 181

@ 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
Run Code Online (Sandbox Code Playgroud)

对于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
Run Code Online (Sandbox Code Playgroud)

  • 任何人都可以解释为什么这需要手动编译,默认情况下不能通过包提供? (46认同)
  • 我一开始犹豫不决,但最后我做了,它完美无缺.正如[gitcredentials文档](https://www.kernel.org/pub/software/scm/git/docs/v1.7.9/gitcredentials.html)所说,你可能也想做`git help -a | grep凭证 - `并查看是否安装了其他帮助程序.默认情况下出现的是"凭证缓存"(输入后一段时间记住密码,默认情况下为15分钟)和"凭证存储"(只需将密码以明文形式存储在磁盘上未加密的文件中,`〜/.git-credentials`默认情况下). (9认同)
  • 仍适用于Ubuntu 16.04 LTS (8认同)
  • 在Ubuntu 14.04 LTS工作! (4认同)
  • 只需要做`chmod 0755 git-credential-gnome-keyring`来向root以外的人添加执行权限 (4认同)
  • @lanoxx:请参阅https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=740739.看起来这只是缺乏维护者的时间/注意力. (4认同)
  • (部分@lanoxx)实际上,一些发行版(例如Fedora和Arch Linux)确实默认提供了已编译的`git-credential-libsecret`二进制文件。请参阅[此Stackoverflow答案](/sf/ask/2560984751/#40312117)。 (3认同)
  • 使用它,但不是在上面指定的文件夹中编译它我将该文件夹复制到〜/ bin,然后在该文件夹中运行make(不带sudo).我现在可以用git config --global credential.helper~/bin/gnome-keyring/git-credential-gnome-keyring开始使用它. (2认同)
  • +1 :) 顺便说一句,如果您使用`sudo make -C /usr/share/doc/git/contrib/credential/gnome-keyring`,您可以摆脱`cd`,保存一行,并且不触及用户的cwd 。 (2认同)

mar*_*hez 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
Run Code Online (Sandbox Code Playgroud)

@VonC解决方案已关闭,但git config命令应该指向可执行文件.这就是为什么它不适合我.

  • 如果您收到“在 pkg-config 搜索路径中找不到软件包 gnome-keyring-1。”,则您缺少 gnome-keyring 的开发库。在 Ubuntu 上,这些可以通过“apt-get install libgnome-keyring-dev”获得。另外,我必须从 https://github.com/git/git/tree/master/contrib 手动下载 git contrib 存储库并将其放入 /usr/share/git-core/ 中。这些文件不再包含在默认的 git 安装中,至少使用官方的 git-core ubuntu ppa 是这样。 (2认同)
  • `libgnome-keyring` [现已弃用](https://wiki.archlinux.org/index.php/GNOME/Keyring) 并且需要安装 `org.freedesktop.secrets` 软件包之一。新的“gnome-keyring”就是其中之一。 (2认同)

Von*_*onC 23

2016年第4季度更新:

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

(请参阅" 如何在Windows登出Git中的Bash控制台? ":这是混帐的Windows使用了最新的Microsoft Git的凭据管理器用于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
Run Code Online (Sandbox Code Playgroud)

在构建时,它将安装在/path/to/git/credential目录中.

要使用此后端,可以通过设置将其添加到(全局)Git配置中

(这里是Unix):

git config --global credential.helper /path/to/git/credential/gnome-keyring/git-credential-gnome-keyring
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

credential.helper=!github --credentials部分将调用凭证助手' github'.

$ git config [--global] credential.helper $BACKEND
Run Code Online (Sandbox Code Playgroud)


vk5*_*5tu 11

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

  • 也许,这应该是对此处任何基于 gnome-keyring 的答案的评论。 (2认同)

Sup*_*reg 10

对于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
Run Code Online (Sandbox Code Playgroud)

  • 在Fedora 21,git 2.1.0中,您可以简单地执行:`git config --global credential.helper gnome-keyring` (10认同)
  • 我很困惑,这不是已经包含在git包中了吗?那么这个文件在fc19包中是什么,git-1.8.3.1-1.fc19.x86_64.这里有这个文件:`/ usr/libexec/git-core/git-credential-gnome-keyring`. (2认同)
  • Fedora 32:“sudo dnf install git-credential-libsecret”,然后“git config --global credential.helper libsecret” (2认同)

oli*_*ver 6

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

[credential]
    helper = gnome-keyring
Run Code Online (Sandbox Code Playgroud)

下次Git要求您输入密码时,输入的密码将保存到Gnome Keyring(您可以通过seahorse工具查看),之后不再要求您输入密码.

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

  • 在Ubuntu 16.04中:`git:'credential-gnome-keyring'不是git命令. (4认同)