Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git .netrc file authentication issue

Tags:

git

github

.netrc

I am using GitHub. I created a repository and cloned it on my Ubuntu machine. I have made an entry in the .netrc file as follows:

machine https://github.com/xxx/yyy.git
login xxx
xxx

I am expecting that Git will not ask me for the username and password after this entry in the .netrc file. But Git prompts for credentials even after this.

Am I missing something?

like image 998
Arul Selvam Avatar asked Jul 24 '15 11:07

Arul Selvam


People also ask

How do I use .netrc file?

netrc file format is simple: you specify lines with a machine name and follow that with the login and password that are associated with that machine. Each field is provided as a sequence of letters that ends with a space or newline. Since 7.84. 0, curl also supports quoted strings.

How do I fix Git always asking for credentials?

You can avoid being prompted for your password by configuring Git to cache your credentials for you. Once you've configured credential caching, Git automatically uses your cached personal access token when you pull or push a repository using HTTPS.

What is .netrc Git?

netrc — Access to git repo without typing password any time (for MacOSX). We're usually using local git configuration to store username and password for access. Especially if you're using https instead of ssh. Most of us are using gihub/gitlab/bitbucket as regular git repositories.

How do I clear my credential cache in Git?

To reset your cached credentials so that Git prompts you to enter your credentials, access the Credential Manager in the Windows Control Panel under User Accounts > Credential Manager. Look for the GitHub entry and delete it.


1 Answers

The ~/.netrc (or %HOME%\_netrc on Windows) file isn't enough.

It is best to use that file encrypted, with gpg + netrc alone, as I did here.

Or to use a script managing the encryption.
You would need, in that second case, to:

  • copy the git-credential-netrc.perl file anywhere in your $PATH/%PATH%,

  • add:

      cd yourRepo
      git config credential.helper "netrc -d -v"
    

(You can remove -d and -v once it is working: those are debug flags)

  • use your login in the remote URL:

      git set-url origin https://[email protected]/yourLogin/yourRepo
    

See "Git - How to use .netrc file on Windows to save user and password" for the general principle of a credential "netrc" helper (Git 1.8.3+).

like image 133
VonC Avatar answered Oct 11 '22 05:10

VonC