Safeguard
Developer Tools•

Does gh auth login store your GitHub token in plain text?

By default the GitHub CLI saves your token in the system credential store. It can fall back to a plain text file, so check how your machine stores it.

Safeguard Security Team
4 min read

Not by default. The GitHub CLI manual says the web login stores the token securely in the system credential store. If no store is found or it fails, gh falls back to a plain text file, and the insecure-storage flag forces that choice. Run gh auth status to see where your token lives.

What the manual says

The gh auth login manual states that the default authentication mode is a web-based browser flow. When that completes, an authentication token is stored securely in the system credential store. If a credential store is not found, or there is an issue using it, gh falls back to writing the token to a plain text file. The gh auth status command shows the stored location.

There is also an --insecure-storage option, which saves credentials in plain text instead of the credential store. It exists for cases where a store is unavailable, and it should not be a default.

When the fallback happens

The fallback is most likely on machines without a desktop keyring, such as a headless Linux server, a minimal container or a remote development box. The CLI cannot talk to a store that is not there, so it writes the file.

On a personal laptop with an operating system keychain, you normally get the secure path. Do not assume, though. A quick check takes seconds.

Three ways to authenticate, compared

MethodWhere the token livesGood for
Browser flow (default)System credential store, with plain text fallbackYour own laptop
--with-token on stdinSame storage rules after loginScripted setup using a token you supply
GH_TOKEN environment variableIn the environment of that processHeadless automation and CI

The manual notes that gh will use a token found in environment variables, which suits automation. It also cautions that for fine-grained personal access tokens you should favour setting GH_TOKEN rather than passing them through --with-token, because the scoping can cause confusing behaviour with other resources. In GitHub Actions, the manual suggests setting GH_TOKEN: ${{ github.token }} in the job environment.

A short checklist

  1. Run gh auth status and note the storage location it reports.
  2. If it points at a plain text file on a machine that has a keyring, log out and log in again after fixing the keyring.
  3. Do not use --insecure-storage on shared or long-lived machines.
  4. Give the token the narrowest scopes your work needs. The manual lists the minimum scopes for --with-token with a classic token.
  5. On servers, prefer a short-lived or narrowly scoped token supplied through the environment for that job.
  6. Revoke tokens you no longer use from your GitHub account settings.

Where Safeguard fits

Safeguard works on the dependency and code side of your software: SBOM and dependency scanning, reachability analysis and policy gates. It does not store or manage credentials, so keep using your password manager, secrets manager or cloud identity for that. You can run a free scan of a project at gold.safeguard.sh/scan.

Quick check

Is the browser login safer than pasting a token?

The manual says the browser flow stores the token in the system credential store, which is the more protective default. Pasting a token still follows the same storage rules.

How do I find where the token is stored?

Run gh auth status. The manual says it shows the stored location.

What should automation use?

The manual points to environment variables such as GH_TOKEN for headless use.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.