When your are behind a corporate proxy it might be difficult to use SSH to communicate with github.com, since this type of traffic may be blocked. A way to get around this is to authenticate over HTTPS instead, and supplying a username and password.
However, if two factor authentication is enabled, as it should be, this method will fail since the current interface does not support this. The solution is to create an authentication token to use for this specific machine.
The even shorter version of this guide is
- Go to the token creation page.
- Click Generate new token.
- Set the following permissions, and let the rest remain unchecked.
reporepo:statusrepo_deploymentpublic_reporepo:invite
gistdelete_repowrite:discussionread:discussion
- Click Generate token.
- Copy the token now as this is the last time you will see it!
This token is now used as a password for authenticating via the CLI, but has limited permissions. As this token is hard to remember you can store this information in a file so authentications are done automatically.
Git is using curl in the background, which will check the file ~/.netrc
to see if there are any credentials that match the current domain.
If it doesn't already exist, create it and add the following:
machine github.com
login <username>
password <token>
protocol https
machine gist.github.com
login <username>
password <token>
protocol https
machine api.github.com
login <username>
password <token>
protocol https
Limit the permisssions of the file.
sudo chmod 600 ~/.netrc
This file is not protected well, so if you are defensive you might want to
uncheck the delete_repo permission as well, as an additional precaution.
Now you should now be able to use GitHub over HTTPS without having to authenticate all the time.