How to use git with gnome-keyring integration

GitGnome

Git Problem Overview


Git 1.8.0 supports integration with gnome-keyring.

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

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)

Git Solutions


Solution 1 - Git

@marcosdsanchez's answer is for Arch (which answers the original question) but I'm on Ubuntu. For 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:

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

Solution 2 - Git

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

This is what solved it for me in 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.

Solution 3 - Git

Update Q4 2016:

  • Unix, Mac (Git 2.11+)

      git config --global credential.helper libsecret
    

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

  • Windows:

      git config --global credential.helper manager
    

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


Original answer (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:

> 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 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/credential directory.

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

(here for Unix):

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

Note for 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.

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

GitHub for Windows provides 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":

C:\Users\VonC\Documents\GitHub\test [master +2 ~0 -0 !]> git config --system -l
credential.helper=!github --credentials

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

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

Solution 4 - Git

Update October 2018

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

git config --global credential.helper libsecret

Solution 5 - Git

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

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

Solution 6 - Git

Just add these two lines to your ~/.gitconfig file:

[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 seahorse tool), and you won't be asked for the password again afterwards.

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

Solution 7 - Git

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-keyring or libsecret versions of the package, something like 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 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

Solution 8 - Git

I was trying the answer for Ubuntu on a headless server and I got the following errors when entering my token:

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

Here is the solution that worked for me on the headless server (see https://keyring.readthedocs.io/en/latest/#using-keyring-on-headless-linux-systems):

  • First I ran the same commands as in the answer to set git-credential-libsecret as the 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
  • Then, whenever I start a session where I will make use of the credentials (e.g. commands like git push), I run:
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

This runs a D-Bus session inside which the I can run for example git push and the likes with automatic authentication.

Solution 9 - Git

On Fedora you need to install

$ sudo dnf install git-credential-libsecret

and edit your git configuration to use the credential helper.

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmarcosdsanchezView Question on Stackoverflow
Solution 1 - GitJames WardView Answer on Stackoverflow
Solution 2 - GitmarcosdsanchezView Answer on Stackoverflow
Solution 3 - GitVonCView Answer on Stackoverflow
Solution 4 - Gitvk5tuView Answer on Stackoverflow
Solution 5 - GitSuperGregView Answer on Stackoverflow
Solution 6 - GitoliverView Answer on Stackoverflow
Solution 7 - GitpalswimView Answer on Stackoverflow
Solution 8 - GitGiuseppeView Answer on Stackoverflow
Solution 9 - GitkinafuView Answer on Stackoverflow