如何使用git与gnome-keyring集成

r3i60tvu  于 2023-05-12  发布在  Git
关注(0)|答案(9)|浏览(201)

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 credentials helpers的文档之后:http://git-scm.com/docs/gitcredentials.html
我无法找到使用这个新功能的方法。我如何整合它?我使用的是Archlinux,从Archlinux的仓库安装了git。(git 1.8.0)

lsmd5eda

lsmd5eda1#

@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
8hhllhi2

8hhllhi22#

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

ki0zmccv

ki0zmccv3#

2016年第四季度更新:

  • Unix,Mac(Git 2.11+)
git config --global credential.helper libsecret

(See“Error when using Git credential helper with gnome-keyring“)

  • 窗口:
git config --global credential.helper manager

(See“How to sign out in Git Bash console in Windows?”:即**Git for Windows**使用最新的Microsoft Git Credential Manager for Windows
提醒:libgnome-keyring是特定于GNOME的,并且是:

原始答案(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配置中
(here对于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
stszievb

stszievb4#

2018年10月更新
GNOME已弃用libgnome-keyring并将其替换为libsecret。Commit https://github.com/git/git/commit/87d1353a6a添加了一个新的凭据帮助器/usr/libexec/git-core/git-credit-libsecret。
git config --global credential.helper libsecret

ykejflvf

ykejflvf5#

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

bd1hkmkf6#

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

[credential]
    helper = gnome-keyring

下次Git要求你输入密码时,输入的密码将保存到Gnome Keyring(你可以使用seahorse工具看到这一点),之后不会再要求你输入密码。
这假设你的Git版本足够新(比如2.1.0),并且你使用的是Linux Fedora、RHEL或CentOS。对于旧版本或其他操作系统/发行版,请查看其他答案。

llew8vvj

llew8vvj7#

在Fedora上,您需要安装

$ sudo dnf install git-credential-libsecret

并编辑你的git配置以使用凭证助手。

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

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

xmq68pz9

xmq68pz98#

一些发行版确实将此集成作为安装包提供,而不需要任何编译。根据您的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
hsvhsicv

hsvhsicv9#

我在 headless server 上尝试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会话,I可以在其中运行例如git push等具有自动身份验证的程序。

相关问题