gh auth login
Three ways to auth
07/27/2025
read time: 1 min
gh auth
is a really nice way to access your Github repos from the command line. But it has always confused me a little bit. I believe there are [three ways] you can auth with gh auth
:
- with an 1) environment variable or 2) stored token
- I believe if
gh auth
is run without the--with-token
flag, it first checks for an environment variable (can beGH_TOKEN
orGITHUB_TOKEN
). If found, it uses that - If no environment variable is found, it looks for a Github token stored credentials (Keychain (mac),
libsecret
(Linux) or Credential Manager (Windows)). If found, it uses that.
- I believe if
gh auth login
(with no environment variable set and no stored token set)- uses the default method, web-based, which is really convenient
- stores an auth token in the system credentials store
gh auth login --with-token
- you can pass in a classic personal access token (must have
repo, read:org and gist
) in standard input - you can also pass in an environment variable here if you like with
echo $GH_TOKEN | gh auth login --with-token
- you can pass in a classic personal access token (must have