Github Access Tokens — 2FA

With the introduction of two-factor authentication, we are now required to change the way we access our repositories. There are now two main methods to upload to Github: using ssh keys or access tokens. This page describes the latter.

Creating a token

  1. Click on your user icon (top-right)
  2. Select Settings
  3. From the left-hand menu, select Developer Settings
  4. Personal Access Tokens
  5. Right-top: Generate New Token

Copy and SAVE the token, you will not get to view it again without generating a new one!

Storing the token

Caching for a TEMPORARY period in time

If we wish to store our token for a fixed period in time we may cache it with a predefined timeout.

git config --global credential.helper 'cache --timeout=31540000'

Here the timeout corresponds to the number of seconds in a year, you can choose a more suitable duration for your work.

Saving the token in $HOME

It is also possible to save it within your home directory as a plaintext file, serving much the same purpose. Just note that you may want to change the viewing permissions to prevent other people from seeing or using your token.

git config --global credential.helper store

Finally, we need to enter the token itself.

We can do this by running a git pull the command from our repository. Here we will be prompted to enter our username and then a ‘password’. This is our newly generated access token from GitHub.

Username for 'https://github.com': <user>Password for 'https://<user>@github.com': <your token>

Research Software Engineer specialising in Data Visualisation with a touch of HPC. — PhD in Atmospheric Chemistry and Masters in Theoretical Physics.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store