Currently, whenever I git pull or git push to a http(s) repository, I get the following:

$ git pull
Username for 'https://gitrepos.reposdomain.com': me@mydomain.com
Password for 'https://me@mydomain.com@gitrepos.reposdomain.com': 

This is ok for infrequent use, but starts to become really annoying very quickly. Unfortunately, switching to ssh is not an option in this case.

I've read that earlier versions of git provided a credential "store" and "cache", but that this wasn't advised because it stored the password in plaintext.

BUT

Newer versions of git apparently store git credentials in the gnome-keyring, but it has to be set up correctly.

I've tried following other (non-Ubuntu) answers on SO to get this to work (namely this one), but I'm still presented with the username and password prompt.

What is the correct and safest way to store git credentials for http(s) repos and how does one make them work on Ubuntu?

  • You should mention which methods you did try. Otherwise you might find answers suggesting exactly those. – muru May 17 '16 at 0:23
  • @muru Why have you removed the emphasis I added for readability? Now it's just a blob of text and the reasons that differentiate the question from others and the actual question is less obvious. – tudor May 17 '16 at 0:26
  • An entire sentence bolded and italicised is hardly readable. – muru May 17 '16 at 0:27
  • @muru I beg to differ. I find bolded and italicised text brings out the essential parts of the question. – tudor May 17 '16 at 0:28
up vote 15 down vote accepted

gnome-credential-helper is now deprecated.

Instead, use libsecret. If it's not already buil-in your ubuntu, use the following procedure:

  1. You can install libsecret and the development libraries with:

    sudo apt-get install libsecret-1-0 libsecret-1-dev

  2. Then you need to build the credential manager

    cd /usr/share/doc/git/contrib/credential/libsecret

    sudo make

  3. Finally, you should point git to the newly created file in your config:

    git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret

More details on https://stackoverflow.com/a/40312117/2017781

  • 1
    You might want to note that this solution only applies to git versions >= 2.11 (where the libsecret dir may then be found) – Charles Roberto Canato Oct 2 '17 at 23:04
  • Is this safe? Where are the secrets stored? Is both the transmission and the storage safe? Is there any official documentation? Apparently, as per this page and this page, it’s in “Main” and maintained by Debian/Ubuntu. And: “It communicates with the 'Secret Service' using DBus.” – caw Jan 23 at 6:14
  • @caw: In GNOME, "Secret Service" is the same gnome-keyring-daemon, just through a different API. (The libsecret plan was to allow other DEs to build their own backends supporting the same API, e.g. KDE planned to implement this in kwalletd.) – grawity Feb 24 at 15:15
  • 2
    Updating my preferred answer as I can verify this works on 18.04. :) – tudor May 9 at 1:02

You need to setup the git credential helper with Gnome Keyring:

Install and compile the Gnome Keyring devel:

sudo apt-get install libgnome-keyring-dev
sudo make --directory=/usr/share/doc/git/contrib/credential/gnome-keyring

And setup the credential:

git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
  • That's really weird. Semantically, there should be no difference between the answer in the link and this answer. But for some reason this answer works where the other doesn't. – tudor May 25 '16 at 13:03
  • Then run git push or git pull as normal and the first time it will ask ansd store, and every time after that it will get it from the keyring. To verify it, run seahorse. It should be listed under "Passwords" ->"Login". – tudor May 25 '16 at 13:06
  • @tudor That's strange, I don't see any "conceptual" difference between my answer and the link one. Glad that it helps. – user98829 May 25 '16 at 20:10
  • Seems weird to me that you still have to run the "make" command, but these steps work great. Thanks! – DaveTheScientist Feb 10 '17 at 20:21

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.