How to use git with gnome-keyring integration
Asked Answered
C

10

151

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)

Crane answered 14/11, 2012 at 19:15 Comment(0)
C
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.

Crane answered 15/11, 2012 at 2:51 Comment(6)
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.Cordelier
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 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.Borek
This pretty well explains why the aur package git-credential-gnomekeyring is gone, too bad that in AUR there's no such information.Hellenist
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...?Masticate
As of 2017 on Arch, simply installing libgnome-keyring is sufficient (at least if you are using gnome).Diabolism
libgnome-keyring is now deprecated and requires one of the org.freedesktop.secrets packages to be installed. Of which the new gnome-keyring is one.Ohalloran
P
228

@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
Poucher answered 25/1, 2013 at 18:45 Comment(27)
I was hesitant to do this at first, but I did finally and it works perfectly. As the docs for gitcredentials 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).Mera
Works in actual Debian testing (jessie) too!Lafferty
Could anyone explain why this needs to be compiled manually and is not available by default through a package?Kassie
Worked in Ubuntu 14.04 LTS!Spheroidal
Verified in Ubuntu 14.10Gorlicki
just had to do chmod 0755 git-credential-gnome-keyring to add execution permission to others than rootSpeedway
Worked for BunsenLabs 8.2Impenitent
After the first step, tried the second and found nothing but osxkeychain inside /usr/share/doc/git/contrib/credentials/. :(Masticate
I don't know what is this doing, but it works like magic! @Xubuntu_14.04.4Seymour
* 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.Helwig
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-keyringPlott
@lanoxx: See bugs.debian.org/cgi-bin/bugreport.cgi?bug=740739 . Looks like it's just a lack of maintainer time/attention.Esoteric
Still valid for Ubuntu 16.04 LTSSpheroidal
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 serviceOutfit
Once I set PKG_CONFIG_PATH, git-credential-gnome-keyring built.Outfit
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.Kat
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.Collide
(Partially @lanoxx) Actually, some distros like Fedora and Arch Linux do provide the compiled git-credential-libsecret binary by default. See this Stackoverflow answer.Chlor
That solution does not seem to work anymore for me on Ubuntu 19.10. E: Unable to locate package libgnome-keyring-devTrodden
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.Trodden
@Mario You need to follow the instructions for git >= 2.11 on Ubuntu 19.10Poucher
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-.Melonymelos
+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.Rabbinism
Debian no longer provides libgnome-keyring or libgnome-keyring-dev 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.Mebane
I needed to install also gnome-keyring package on Debian buster.Malign
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.Coraciiform
It works well for Ubuntu 22.04.1 LTS with git 2.34.1Roana
C
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.

Crane answered 15/11, 2012 at 2:51 Comment(6)
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.Cordelier
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 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.Borek
This pretty well explains why the aur package git-credential-gnomekeyring is gone, too bad that in AUR there's no such information.Hellenist
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...?Masticate
As of 2017 on Arch, simply installing libgnome-keyring is sufficient (at least if you are using gnome).Diabolism
libgnome-keyring is now deprecated and requires one of the org.freedesktop.secrets packages to be installed. Of which the new gnome-keyring is one.Ohalloran
C
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
Cordelier answered 14/11, 2012 at 20:2 Comment(5)
Not what I'm looking for. The answer should be *nix only.Crane
@Crane ok, I have edited my answer to include a setup and usage of gnome-keyring on Unix with Git.Cordelier
I want to use git's 1.8.0 feature, which is already there. Not third party code. Thanks.Crane
@Crane then you need to compile github.com/git/git/tree/master/contrib/credential/gnome-keyring (which is packaged with git). Once compiled, you would install and use it as illustrated in my answer.Cordelier
I guess there's no binary built-in?Crane
T
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

Thimbu answered 11/10, 2018 at 3:50 Comment(2)
Probably, this should be a comment on any gnome-keyring based answer here.Phenacetin
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.Trodden
M
10

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
Mordy answered 17/1, 2014 at 17:28 Comment(4)
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.Archway
In Fedora 21, git 2.1.0, you can simply do: git config --global credential.helper gnome-keyringHandstand
Fedora 32: sudo dnf install git-credential-libsecret then git config --global credential.helper libsecretThimbu
This method is outdated to nowEohippus
G
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.

Greenes answered 30/6, 2017 at 13:5 Comment(3)
In Ubuntu 16.04: git: 'credential-gnome-keyring' is not a git command.Gumption
@Saibot: whoops, you're right. Looks like Fedora/RHEL provide this, but Ubuntu doesn't. So the answer by James Ward (https://mcmap.net/q/13472/-how-to-use-git-with-gnome-keyring-integration) is better in that case.Greenes
In RHEL you need to install git-gnome-keyring if not already done.Landeros
P
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.

Pivoting answered 29/3, 2020 at 12:35 Comment(0)
C
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
Cynthia answered 5/11, 2019 at 6:14 Comment(2)
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: github.com/timhughes/git-credential-libsecretTrodden
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.Degraw
N
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.

Notary answered 15/4, 2021 at 19:55 Comment(2)
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?Differentiation
@Differentiation 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.Notary
S
2

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.

Stella answered 28/5, 2023 at 7:15 Comment(1)
The pointer to git-credential-oauth is the simplest solution for most users now.Pubes

© 2022 - 2024 — McMap. All rights reserved.