如何将 git 与 gnome-keyring 集成一起使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13385690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:55:40  来源:igfitidea点击:

How to use git with gnome-keyring integration

gitgnome

提问by marcosdsanchez

Git 1.8.0 supports integration with 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

http://www.h-online.com/open/news/item/Git-1-8-0-can-access-Windows-and-GNOME-keyrings-1733879.html

After reading the docs about the git credentials helpers: http://git-scm.com/docs/gitcredentials.html

阅读有关 git 凭证助手的文档后:http: //git-scm.com/docs/gitcredentials.html

I was not able to find a way to use this new feature. How can I integrate it? I'm using Archlinux with git installed from Archlinux's repository. (git 1.8.0)

我无法找到使用此新功能的方法。我怎样才能集成它?我正在使用 Archlinux 和从 Archlinux 的存储库安装的 git。(git 1.8.0)

采纳答案by marcosdsanchez

Git 1.8.0 comes with gnome-keyring support but the binary needs to be compiled for your platform.

Git 1.8.0 带有 gnome-keyring 支持,但二进制文件需要为您的平台编译。

This is what solved it for me in Archlinux:

这就是在 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 solution was close, but the git config command should point to the executable. That's why it was not working for me.

@VonC 解决方案很接近,但 git config 命令应该指向可执行文件。这就是为什么它对我不起作用。

回答by James Ward

@marcosdsanchez's answer is for Arch (which answers the original question) but I'm on Ubuntu. For git >= 2.11:

@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

For git < 2.11:

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

回答by VonC

Update Q4 2016:

2016 年第四季度更新:

  • Unix, Mac (Git 2.11+)

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

    git config --global credential.helper libsecret
    

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

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

  • Windows:

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

    git config --global credential.helper manager
    

(See "How to sign out in Git Bash console in Windows?": That is Git for Windowsusing the latest Microsoft Git Credential Manager for Windows)

(请参阅“如何在Windows登出Git中的Bash控制台?”:这是混帐的Windows使用最新的微软Git的凭据管理器用于Windows



Original answer (2012)

原始答案 (2012)

Credential Helpers, for Windows, Mac and Unix platforms, have been introduced first in "git-credential-helper" repo, which now has been included in git distro:

Credential Helpers,适用于 Windows、Mac 和 Unix 平台,首先在“git-credential-helper”repo 中引入,现在已包含在 git distro 中

This repository contains the set of Git credential helpers (gitcredentials(7)) that are part of git(or meant to be contributed in the future).

此存储库包含一组 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

when build, it would be install in /path/to/git/credentialdirectory.

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

To use this backend, you can add it to your (global) Git configuration by setting

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

(here for Unix):

(此处适用于 Unix):

git config --global credential.helper /path/to/git/credential/gnome-keyring/git-credential-gnome-keyring


Note for Windows:

Windows 注意事项:

I suppose you could make a program running on Windows and calling a library like "pypi keyring 0.10.
But that is the back-end, and you don't use it directly from Git.

我想你可以让一个程序在 Windows 上运行并调用一个库,比如“ pypi keyring 0.10
但那是后端,你不直接从 Git 使用它。

What you are using is a "credential helper" (which, in turn, will call any credential API it wants on Windows).

您正在使用的是“凭据帮助程序”(反过来,它将在 Windows 上调用它想要的任何凭据 API)。

GitHub for Windowsprovides such an helper (as an executable called... github), and can store your credentials for the duration of the Windows session.
Launch a shell from that "GitHub for Windows" windows, and you will see, typing "git config --system -l":

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

The credential.helper=!github --credentialspart will call the credential helper 'github'.

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

$ git config [--global] credential.helper $BACKEND

回答by vk5tu

Update October 2018

2018 年 10 月更新

GNOME has deprecated libgnome-keyring and replaced it with libsecret. Commit https://github.com/git/git/commit/87d1353a6aadded a new credential helper /usr/libexec/git-core/git-credential-libsecret.

GNOME 已弃用 libgnome-keyring 并将其替换为 libsecret。提交https://github.com/git/git/commit/87d1353a6a添加了一个新的凭证助手 /usr/libexec/git-core/git-credential-libsecret。

git config --global credential.helper libsecret

git config --global credential.helper libsecret

回答by SuperGreg

For anyone on Fedora, I edited James Ward's answer slightly:

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

回答by oliver

Just add these two lines to your ~/.gitconfigfile:

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

[credential]
    helper = gnome-keyring

Next time you are asked for a password by Git, the entered password will be saved to Gnome Keyring (you can see this with seahorsetool), and you won't be asked for the password again afterwards.

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

This assumes that your Git version is sufficiently new (like 2.1.0) and you are under LinuxFedora, RHEL or CentOS. For older versions or other OSs/distros check out the other answers.

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

回答by palswim

Some distributions do come with this integration as an installation package, without requiring any compilation. Depending on your version of GNOME, you will need to install either gnome-keyringor libsecretversions of the package, something like git-credential-gnome-keyring(OpenSUSE Leap 42.3).

某些发行版确实将此集成作为安装包提供,无需任何编译。根据您的 GNOME 版本,您需要安装软件包的一个gnome-keyring或多个libsecret版本,例如git-credential-gnome-keyring(OpenSUSE Leap 42.3)。

However, this in itself will not enable Git integration with the GNOME Keyring automatically. You must still configure Git to use this method of credential storage:

但是,这本身不会自动启用 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

回答by kinafu

On Fedora you need to install

在 Fedora 上,您需要安装

$ sudo dnf install git-credential-libsecret

and edit your git configurationto use the credential helper.

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

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

FYI the libsecretpackage has recently been split up, see post from @rugk. That's why users need to reinstall this package.

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