Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub, HTTPS and Mac application

Tags:

git

github

macos

I know SSH in GitHub causes no problem (no username/password to type everytime i.e.), but I need to use HTTPS for a repo of mine.

Now, I git inited the repo, I committed, I did a git remote add origin https://github.com/user/repo.git as suggested by GitHub.

I was about to do a git push -u origin master: first it promped me for username and password, and then answered with:

remote: Anonymous access to user/repo.git denied.
fatal: Authentication failed for 'https://github.com/user/repo.git/'

I'm 300% sure I typed the right password (and I tried again a couple times anyway). I googled here and there, and then I tried my last chance: installing the GitHub app for Mac. I entered my credentials, entered the 2-factor auth code they sent me, and tried to push again: this time it worked.

Why? What did the GitHub app do behind the scenes? Has it something to do with the 2-factor auth?

Anyway, I would be able to not download the app on every machine I setup, maybe by automating this process with some script.

like image 650
whatyouhide Avatar asked Oct 07 '13 10:10

whatyouhide


1 Answers

Your GitHub password won't work if you have activated the two-factor authentication.

You need to generate a Personal Access Token, as I explain in "Configure Git clients, like GitHub for Windows, to not ask for authentication".

That long (40 characters) password will work as your GitHub password without requiring a second authentication.

The difference between a PAT (Personnal Access token) and your Github password account:

  • It doesn't required the second step, but:
  • it is more complex than a simple password (not meant to be remembered)
  • you can generate as many as you want (one for each different computer from which you access GitHub, for instance)
  • you can revoke it at any time (easier than having to change your GitHub password)

And you can encrypt your GitHub credential in a .netrc.gpg file, as I illustrate in "Is there a way to skip password typing when using https:// github".
I find that far superior to a memory-caching mechanism (like credential-osxkeychain), since you don't have to type your GitHub (long and complex token) password at each session.
You only type the passphrase of your gpg key, for that GitHub login/token credential, or for any other credential that you have encrypted in your ~/.netrc.gpg file.

like image 191
VonC Avatar answered Oct 04 '22 14:10

VonC