149

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)

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
marcosdsanchez
  • 2,529
  • 2
  • 17
  • 20

10 Answers10

229

@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
James Ward
  • 29,283
  • 9
  • 49
  • 85
  • 12
    I was hesitant to do this at first, but I did finally and it works perfectly. As the [docs for gitcredentials](https://www.kernel.org/pub/software/scm/git/docs/v1.7.9/gitcredentials.html) say, you might also want to do `git help -a | grep credential-` and see if you have other helpers installed. Ones that come by default are `credential-cache` (remember password for some time after you enter it, 15 minutes by default), and `credential-store` (just store the password in plaintext on an unencrypted file on disk, `~/.git-credentials` by default). – ShreevatsaR Dec 24 '13 at 05:18
  • 1
    Works in actual Debian testing (jessie) too! – MyChaOS Mar 29 '14 at 21:45
  • 68
    Could anyone explain why this needs to be compiled manually and is not available by default through a package? – lanoxx Jul 12 '14 at 15:31
  • 4
    Worked in Ubuntu 14.04 LTS! – Eugene Kulabuhov Dec 19 '14 at 00:55
  • 1
    Verified in Ubuntu 14.10 – craigb Mar 25 '15 at 20:58
  • 4
    just had to do `chmod 0755 git-credential-gnome-keyring` to add execution permission to others than root – Lari Hotari Oct 14 '15 at 12:40
  • Worked for BunsenLabs 8.2 – Mateusz Piotrowski Mar 13 '16 at 23:02
  • After the first step, tried the second and found nothing but osxkeychain inside /usr/share/doc/git/contrib/credentials/. :( – temporary_user_name Mar 21 '16 at 16:01
  • I don't know what is this doing, but it works like magic! @Xubuntu_14.04.4 – Ufos Jun 03 '16 at 14:47
  • * Ubuntu 16.10 Tried running this: $ sudo make Got the error: make: Nothing to be done for 'all'. Then I tried this: $ sudo make git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring Got the error: make: unrecognized option '--global' Usage: make [options] [target] ... I have a feeling this will also work on Ubuntu 16.10, but I do not know how could I make it work. – Borgy Manotoy Nov 23 '16 at 12:39
  • Sounds like it came with the binary already? Try just `git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-cred‌​ential-gnome-keyring` – Alyssa Haroldsen Jan 21 '17 at 21:35
  • 4
    @lanoxx: See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=740739 . Looks like it's just a lack of maintainer time/attention. – Will Manley Mar 15 '17 at 14:01
  • 8
    Still valid for Ubuntu 16.04 LTS – Eugene Kulabuhov Apr 20 '17 at 14:39
  • Am I the only person who can't compile this on Ubuntu 16.04?? `git-credential-gnome-keyring.c:29:18: fatal error: glib.h: No such file or directory compilation terminated.` `dpkg -l|egrep "libgnome-keyring-dev|libglib2.0-dev" ii libglib2.0-dev 2.48.2-0ubuntu1 amd64 Development files for the GLib library ii libgnome-keyring-dev 3.12.0-1build1 amd64 Development files for GNOME keyring service` – Dave Wongillies Aug 07 '17 at 18:47
  • Once I set `PKG_CONFIG_PATH`, `git-credential-gnome-keyring` built. – Dave Wongillies Aug 07 '17 at 18:52
  • 1
    Tried and tried but only ever get `CRITICAL **: Error communicating with gnome-keyring-daemon` when attempting to pull from master, and am prompted for my creds. Ubuntu 14.04, git 2.16.1. – Madbreaks Jan 29 '18 at 23:23
  • 2
    Used this but instead of compiling it in the folder specified above I copied that folder to ~/bin, then ran make (without sudo) inside that folder. I could now do git config --global credential.helper ~/bin/gnome-keyring/git-credential-gnome-keyring to start using it. – Erik I Mar 27 '18 at 13:01
  • 3
    (Partially @lanoxx) Actually, some distros like Fedora and Arch Linux do provide the compiled `git-credential-libsecret` binary by default. See [this Stackoverflow answer](https://stackoverflow.com/questions/36585496/error-when-using-git-credential-helper-with-gnome-keyring-as-sudo/40312117#40312117). – rugk Mar 13 '19 at 14:03
  • That solution does not seem to work anymore for me on Ubuntu 19.10. `E: Unable to locate package libgnome-keyring-dev` – Mario Jan 08 '20 at 11:54
  • `sudo make` in the corresponding directory results in: `No package 'gnome-keyring-1' found`. The latter package does neither exist. `gnome-keyring` does not seem to be an option. – Mario Jan 08 '20 at 12:01
  • @Mario You need to follow the instructions for `git >= 2.11` on Ubuntu 19.10 – James Ward Jan 08 '20 at 18:37
  • 1
    For a nice clean installation: Mark temporary dev dependencies for auto-removal with `sudo apt-mark auto libsecret-1-dev libglib2.0-dev` if you won't need them after compilation. After make, move the compiled program `sudo mv git-credential-libsecret /usr/local/bin/git-credential-libsecret` and then remove the `.o` file generated with `sudo make clean`. This way, you can simply do `sudo git config --system credential.helper libsecret`. It will also be listed under `git help -a | grep credential-`. – geekley Aug 18 '20 at 09:50
  • 2
    +1 :) Btw if you use `sudo make -C /usr/share/doc/git/contrib/credential/gnome-keyring` you can get rid of the `cd`, save a line, and not touch the user's cwd. – Bean Taxi Jan 07 '21 at 19:38
  • Debian [no longer provides `libgnome-keyring` or `libgnome-keyring-dev`](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=892359) so `git-credential-gnome-keyring` is no longer an option. However, they recommend using `libsecret`, which exists right next door in `/usr/share/doc/git/contrib/credential/libsecret`... going to try it out. – Jonathon Reinhart Apr 12 '21 at 03:29
  • I needed to install also `gnome-keyring` package on Debian buster. – bogec Apr 23 '21 at 12:20
  • This worked for Ubuntu 18.04.5 LTS. I had already tried the gnome-keyring approach which didn't work as it is outdated now. Not sure if that earlier installation was required, but I only had to enter my credentials one more time after using this solution. – yellowjacket05 Jun 06 '21 at 02:23
  • It works well for Ubuntu 22.04.1 LTS with git 2.34.1 – Richard Feb 03 '23 at 11:08
60

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.

marcosdsanchez
  • 2,529
  • 2
  • 17
  • 20
  • I have reformatted my answer to reflect your conclusion. I have built it (it wasn't build by default in my git 1.8 distro) and tested it this morning. It does work. – VonC Nov 15 '12 at 06:50
  • 2
    If you are getting `Package gnome-keyring-1 was not found in the pkg-config search path.` you are missing the dev libraries for gnome-keyring. On Ubuntu these are available with `apt-get install libgnome-keyring-dev`. Also, I had to download the git contrib repo manually from https://github.com/git/git/tree/master/contrib and put it in /usr/share/git-core/. These files are no longer included with a default git install, at least using the official git-core ubuntu ppa. – Johann Jan 08 '13 at 20:39
  • 1
    This pretty well explains why the aur package `git-credential-gnomekeyring` is gone, too bad that in AUR there's no such information. – ryenus Apr 19 '13 at 06:45
  • On ubuntu I have no git folder in `/usr/share/`...only gitweb and git-core. But I am on Git 1.7.9. Could that be why...? – temporary_user_name Mar 21 '16 at 15:55
  • 1
    As of 2017 on Arch, simply installing `libgnome-keyring` is sufficient (at least if you are using gnome). – ald.li Oct 09 '17 at 10:09
  • 3
    `libgnome-keyring` [is now deprecated](https://wiki.archlinux.org/index.php/GNOME/Keyring) and requires one of the `org.freedesktop.secrets` packages to be installed. Of which the new `gnome-keyring` is one. – Peilonrayz Jan 31 '21 at 17:17
29

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)

Reminder: libgnome-keyring is specific to GNOME and is:


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 built, it would be installed 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 a 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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
21

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

vk5tu
  • 381
  • 3
  • 4
  • 2
    Probably, this should be a comment on any gnome-keyring based answer here. – Murmel Aug 07 '19 at 07:28
  • Agree, `gnome-keyring` based answers should be edited accordingly. Maybe just exclude the whole option. That didn't work at all for me on Ubuntu 19.10. – Mario Jan 08 '20 at 12:10
11

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
SuperGreg
  • 119
  • 1
  • 5
  • 3
    I'm confused, isn't this already included with the git packages? What is this file then within the fc19 package, git-1.8.3.1-1.fc19.x86_64. There's this file here: `/usr/libexec/git-core/git-credential-gnome-keyring`. – slm Jan 16 '15 at 15:31
  • 10
    In Fedora 21, git 2.1.0, you can simply do: `git config --global credential.helper gnome-keyring` – RedPoppy Feb 02 '15 at 13:26
  • 4
    Fedora 32: `sudo dnf install git-credential-libsecret` then `git config --global credential.helper libsecret` – vk5tu Sep 29 '20 at 10:53
8

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.

oliver
  • 6,204
  • 9
  • 46
  • 50
  • 8
    In Ubuntu 16.04: `git: 'credential-gnome-keyring' is not a git command.` – Ferit Nov 25 '17 at 16:08
  • @Saibot: whoops, you're right. Looks like Fedora/RHEL provide this, but Ubuntu doesn't. So the answer by James Ward (https://stackoverflow.com/a/14528360/2148773) is better in that case. – oliver Nov 27 '17 at 09:01
  • In RHEL you need to install git-gnome-keyring if not already done. – Alejandro López Sep 18 '20 at 14:13
4

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.

kinafu
  • 516
  • 4
  • 5
3

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
palswim
  • 11,856
  • 6
  • 53
  • 77
  • 1
    On Ubuntu 19.10, the `gnome-keyring` option does no more work for me, but James Ward's instruction using `libsecret` still works well. I was, however, confused by the recommendation to use `gnome-keyring` given here: https://github.com/timhughes/git-credential-libsecret – Mario Jan 08 '20 at 12:07
  • `libsecret` (or what `find /usr -iname git-credential-libsecret` gives) is the right option in Gentoo Linux. Note that `dev-vcs/git` must be emerged with `USE=gnome-keyring`. – sphakka Mar 23 '20 at 09:00
3

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.

Giuseppe
  • 171
  • 1
  • 8
  • 1
    I feel this answer comes close, but opening a new shell process and starting a daemon just to run my git commands is almost as much hassle as just typing in the credentials every time. Can't you run the dbus without a new shell process? – jiggunjer Nov 27 '21 at 21:18
  • @jiggunjer That's a good point. What I personally do is that I am working inside a Tmux session on the remote machine. This way I only had to run the above commands once: every time I resume my work on the remote machine, I reattach the Tmux session, where the daemon is still running. – Giuseppe Dec 02 '21 at 10:04
1

Arch Linux's git package includes git-credential-libsecret (which replaced git-credential-gnome-keyring), so you can run:

git config --global credential.helper libsecret

As an alternative to entering passwords or personal tokens, you can also try git-credential-oauth.

No more passwords! No more personal access tokens! No more SSH keys!

A Git credential helper that securely authenticates to GitHub, GitLab, BitBucket and other forges using OAuth.

The first time you push, the helper will open a browser window to authenticate. Subsequent pushes within storage lifetime require no interaction.

This is compatible with any storage helper including git-credential-cache or git-credential-libsecret.

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465