Wednesday, December 17, 2014

Github - Two-Factor Authentication and HTTPS pull and push

Once you enabled "Two-Factor" authentication in your Github account, you can't push or pull to any of your repositories anymore through HTTPS. You need to create a "Personal Access Token" to be able to push over HTTPS again.

Setting up "Personal Access Token":
1. Log into your Github account.
2. Go into "Account Settings".
3. Go to "Applications" -> "Personal access tokens".
4. Generate your own token.

Save your token into some encrypted file.

To test your token:
$ curl -u your_token_without_square_bracket:x-oauth-basic https://api.github.com/user

You should see something like:
{
  "login": "xxxx",
  "id": 234233,
  "avatar_url": "https://avatars.githubusercontent.com/u/234233?v=3",
  "gravatar_id": "",
  "url": "https://api.github.com/users/xxxx",
  "html_url": "https://github.com/xxxx",
  "followers_url": "https://api.github.com/users/xxxx/followers",
  "following_url": "https://api.github.com/users/xxxx/following{/other_user}",

To let git command pick it up automatically:
Add the following into your ~/.netrc file:
machine github.com
login username
password <your_token>
protocol https

Now you can push and pull, happy coding!

1 comment:

az said...

thanks