Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use git with gnome-keyring integration

Tags:

git

gnome

People also ask

What is GNOME Keyring used for?

GNOME Keyring is a collection of components in GNOME that store secrets, passwords, keys, certificates and make them available to applications. GNOME Keyring is integrated with the user's login, so that their secret storage can be unlocked when the user logins into their session.

Is GNOME Keyring secure?

All secret data in the keyring is encrypted using the highly secure AES-128, and cannot be decrypted in the absence of the password.


@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

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.


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

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


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

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.