Skip to main content

Command referencegh auth login

gh auth login command (Linux & Windows / GitHub CLI)

Linux & WindowsGitHub CLIgitbeginner

What it does

Authenticate the GitHub CLI with GitHub.com or GitHub Enterprise so other gh commands can run. When people search for gh auth login, they usually want practical GitHub CLI flags, safe examples, and how this subcommand fits everyday PR and repo workflows on Linux, Windows, and macOS. Syntax, options, and copyable examples are below.

Authenticate the GitHub CLI with GitHub.com or GitHub Enterprise so other gh commands can run.

Syntax

gh auth login [flags]

Common options

Flag / optionMeaning
-h, --hostnameGitHub hostname (default github.com).
-p, --git-protocolPrefer https or ssh for git operations.
-w, --webOpen a browser to complete login.
-s, --scopesAdditional OAuth scopes to request.
--with-tokenRead a token from standard input (scripts only).

Practical examples

Interactive login

gh auth login

Walks through host, protocol, and browser or token authentication.

Browser flow

gh auth login -w

Opens the browser to authorize the GitHub CLI app.

Prefer SSH

gh auth login -p ssh

Configures git remotes to use SSH after login.

Enterprise host

gh auth login -h github.example.com

Authenticates against a GitHub Enterprise Server hostname.

Common mistakes

  • Pasting a personal access token into chat logs or committed scripts.
  • Skipping login and wondering why later gh commands return HTTP 401.

FAQ

What does gh auth login do in GitHub CLI?

Authenticate the GitHub CLI with GitHub.com or GitHub Enterprise so other gh commands can run.

Does gh auth login work on Windows and Linux?

Yes. The GitHub CLI (`gh`) runs on Linux, Windows, and macOS with the same subcommand syntax after you authenticate with `gh auth login`.

What is a practical gh auth login example?

Try `gh auth login` — Walks through host, protocol, and browser or token authentication.

Do I need a token in the command line for gh auth login?

Prefer `gh auth login` so credentials stay in the system keyring or secure storage. Avoid pasting personal access tokens into shell history.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.