Skip to content

How to set up passwordless authentication for GitHub

Keith Beattie edited this page Aug 18, 2021 · 6 revisions

Intro

Abbreviations

  • PAT: Personal Authentication Token

Using Git Credential Manager

  • Download the latest EXE from the Releases page https://github.com/microsoft/Git-Credential-Manager-Core/releases/, choosing the gmcoreuser-win...exe version ("user" being the version that can be installed and used without admin access)
  • Install the downloaded EXE file normally (I don't remember if there are any options; if so, just choose whatever the default is)
  • Using your usual Git client, perform any operation that requires GitHub authentication
  • If everything is configured correctly, halfway through the Git command it should automatically open a window asking for either a PAT, or to continue with browser authentication. You can choose the latter, and a browser window or tab will be created to perform the authentication
  • Follow the prompts, choosing the default options if needed
  • Once that is done, the Git operation should proceed, and further similar Git commands should be performed directly without requiring authenticating again

Using git CLI credential storage

The git command-line tool can cache your PAT in memory for a period of time, or store it (unencrypted) locally to save you from having to type it in each and every time (after entering it in the first time). Details are here: https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage

Examples are (only use one of these):

git config --global credential.helper cache                    # cache in memory for 15mins
git config --global credential.helper 'cache --timeout 3600'   # cache for an hour 
git config --global credential.helper store                    # Store unencrypted PAT in ~/.git-credentials
git config --global credential.helper 'store --file ~/.creds   # Store unencrypted PAT in ~/.creds

These commands simply just add to your ~/.gitconfig and write in a [credential] section.

On MacOS the OSX KeyChain may be used by the cache helper. Run:

git config --get credential.helper

to see which credential helper is being used.

Using the conda install of git on Windows

It appears that when installing git in a conda environment (via conda install git) the above Git Credential Manager is also installed. So that step of installing it, could be replaced with installing git via conda instead.