What you see
The normal flow prints this and waits for the browser to report back:
Attempting to open authentication page in your browser.
Otherwise navigate to:
https://accounts.google.com/...
Waiting for authentication...
When it goes wrong, the source code has three messages that all end in the same advice:
Failed to open browser with error: ...
Please try running again with NO_BROWSER=true set.
Authentication timed out after 5 minutes. The browser tab may have gotten stuck in a loading state. Please try again or use NO_BROWSER=true for manual authentication.
Authentication consent could not be obtained.
Please run Gemini CLI in an interactive terminal to authenticate, or use NO_BROWSER=true for manual authentication.
How the NO_BROWSER login works
- Set the variable for that run:
NO_BROWSER=true gemini(bash, zsh), or$env:NO_BROWSER="true"thengemini(PowerShell). - Choose Sign in with Google. It prints
Please visit the following URL to authorize the application:and a link. - Open the link anywhere, even on your phone, and sign in. Google sends you to codeassist.google.com/authcode with the code.
- Paste it at
Enter the authorization code:. You have 5 minutes, and it allows two attempts.
Your login is then cached, by default in ~/.gemini/oauth_creds.json, so later sessions start without signing in.
When Gemini CLI skips the browser on purpose
It goes straight to the URL-and-code flow, as if NO_BROWSER were set, when:
BROWSERis set towww-browser;CIis set, orDEBIAN_FRONTEND=noninteractive;- on Linux, none of
DISPLAY,WAYLAND_DISPLAYorMIR_SOCKETis set (servers, most containers); - on macOS or Windows, you are in an SSH session (
SSH_CONNECTIONis set).
Causes and fixes
| Symptom | Cause | Fix |
|---|---|---|
Failed to open browser with error | No program could open the URL, for example xdg-open missing in a minimal container | NO_BROWSER=true |
| Browser opens, you sign in, the terminal still waits, then times out | The sign-in redirect goes to http://127.0.0.1:<port>/oauth2callback on the machine running Gemini CLI, and never got there | Retry once; otherwise NO_BROWSER=true |
| Running in Docker and you want the browser flow | The callback listener binds to 127.0.0.1 inside the container on a random port | The source reads OAUTH_CALLBACK_HOST (its comment gives 0.0.0.0 for Docker) and OAUTH_CALLBACK_PORT for a fixed port you can publish. NO_BROWSER=true is simpler |
Manual authorization is required but the current session is non-interactive | A script or pipe can't paste a code | Sign in once interactively, or use an API key (below) |
Authentication consent could not be obtained | Gemini CLI couldn't ask "Do you want to continue?" in this terminal | Run it in an interactive terminal, or NO_BROWSER=true |
Skip the Google login: use an API key
Scripts, CI and headless mode can't do an interactive Google login, and Gemini CLI's docs point them to environment-variable auth: a GEMINI_API_KEY from Google AI Studio, or Vertex AI. Set the key, start gemini and choose Use Gemini API key. Inside a session, /auth opens the dialog to change sign-in method. API-key quotas differ from Google-login quotas; see Gemini CLI 429.
Still failing?
unable to get local issuer certificateduring sign-in means a corporate proxy is inspecting TLS. TryNODE_USE_SYSTEM_CA=1first, thenNODE_EXTRA_CA_CERTSpointing at your company's root certificate.- Company, school or Workspace accounts need
GOOGLE_CLOUD_PROJECTset to a project ID before signing in. - Exit code 41 is Gemini CLI's
FatalAuthenticationError: sign-in failed, so read the message printed above it.
Running Claude Code, Codex or Cursor on real repos, or shipping an AI agent? A Quick Review ($149 / ₹13,900, 1 working day) checks one repo, config or setup for leaked keys, risky agent permissions and MCP servers. Request a Quick Review
FAQ
How do I log in to Gemini CLI over SSH?
Run NO_BROWSER=true gemini, choose Sign in with Google, open the printed URL in a browser on your own machine, and paste the authorization code back into the SSH session.
What does NO_BROWSER=true do in Gemini CLI?
It stops Gemini CLI from trying to open a browser. It prints a sign-in URL and asks you to paste the authorization code shown after you sign in.
Can I use Gemini CLI in CI without a browser?
Not with Google login, which needs an interactive terminal. Gemini CLI's docs say to use a GEMINI_API_KEY or Vertex AI credentials from environment variables.
Where does Gemini CLI store my Google login?
In ~/.gemini/oauth_creds.json by default, unless encrypted credential storage is turned on.
Related errors
- Gemini CLI error 429 Resource exhausted
- Claude Code: Failed to authenticate / 403
- Codex not working on Windows
Sources
Read 30 Nov 2026. These tools change often: if a step no longer matches, the linked page wins.
- Gemini CLI docs: Authentication: github.com/google-gemini/gemini-cli/blob/main/docs/get-started/authentication.mdx
- google-gemini/gemini-cli source: code_assist/oauth2.ts: github.com/google-gemini/gemini-cli/blob/main/packages/core/src/code_assist/oauth2.ts
- google-gemini/gemini-cli source: utils/browser.ts: github.com/google-gemini/gemini-cli/blob/main/packages/core/src/utils/browser.ts
- google-gemini/gemini-cli source: utils/authConsent.ts: github.com/google-gemini/gemini-cli/blob/main/packages/core/src/utils/authConsent.ts
- google-gemini/gemini-cli source: cli/src/config/config.ts (NO_BROWSER): github.com/google-gemini/gemini-cli/blob/main/packages/cli/src/config/config.ts
- Gemini CLI docs: Troubleshooting: github.com/google-gemini/gemini-cli/blob/main/docs/resources/troubleshooting.md
- Gemini CLI docs: Commands: github.com/google-gemini/gemini-cli/blob/main/docs/reference/commands.md
- Exposed API key checker: find API keys committed to a repo or shipped to the browser
- LLM API cost checker: find LLM calls with no limits or retries capped
- reviewready CLI: one command that checks an AI app repo before it ships