Skip to content

Instantly share code, notes, and snippets.

@bef
Created February 28, 2020 09:48
Show Gist options
  • Save bef/37d481764819187bad996cef0a30143b to your computer and use it in GitHub Desktop.
Save bef/37d481764819187bad996cef0a30143b to your computer and use it in GitHub Desktop.
How to securely handle Github auth tokens with homebrew or avoid them entirely

Problem

Homebrew likely needs a Github API auth token to work correctly, at least with 2FA enabled Github accounts. The Internet - e.g. https://gist.github.com/willgarcia/7347306870779bfa664e - suggests to add the token to your environment via .bashrc, which is generally a bad idea and gives every started program access to your github account.

Solution 1: Shell wrapper

  1. Generate access token via https://github.com/settings/tokens
  2. Wrap your Access token in a shell script, e.g. ~/bin/brew, or whatever is in your path before the actual brew path:
#!/bin/bash
HOMEBREW_GITHUB_API_TOKEN=xxxx /usr/local/bin/brew "$@"

Solution 2: SSH authentication

Rewrite HTTPS to SSH when accessing github via git:

git config --global --add url."[email protected]:".insteadOf "https://github.com/"

see also: https://jacopretorius.net/2018/05/git-error-could-not-read-username.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment