Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

gcloud init cannot finish the sign-in step

ErrorError while trying to authenticate with gcloud init

Short answer

gcloud init signs in through a browser. On WSL, an SSH session or a container no browser opens, so authorization never completes. Run gcloud init with --no-browser if you have a second machine with gcloud, or with --no-launch-browser to paste a code, or use a service account.

  • Applies to Google Cloud CLI, Windows Subsystem for Linux 2, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the sign-in on its own, so the failure is not mixed up with project setup. If it prints a URL instead of opening a window, the browser is the missing piece.

    gcloud auth login
  2. 2Match what you see, then jump to its fix

    1. 1The sign-in tab never opens, or the command waits forever.No browser can be opened on this machine, but another machine has gcloudFix
    2. 2You can only reach a browser on a device that has no gcloud, such as a phone.No browser and no second machine with gcloudFix
    3. 3The machine is unattended, such as a build server, and nobody can complete a prompt.A script or server should not use a person's login at allFix

What does the error look like?

  • Error while trying to authenticate with gcloud init
  • Enter authorization code
  • Enter the output of the above command

Cause 1 of 3

No browser can be opened on this machine, but another machine has gcloud

1Check

The no-browser flow needs gcloud CLI 372.0 or later on a trusted second machine that has a browser. Check the version there.

gcloud version

2Fix

Start sign-in with --no-browser, copy the long command that begins with gcloud auth login --remote-bootstrap, run it on the trusted machine, and paste the URL it prints back into the first prompt.

gcloud init --no-browser
# on the trusted machine, run the command it printed:
# gcloud auth login --remote-bootstrap="..."

3Verify

The first machine continues to the project step and lists your account.

gcloud auth list

Confirmed by docs.cloud.google.com

Did this fix it?

Cause 2 of 3

No browser and no second machine with gcloud

1Check

The docs name a second flow for this case: print the URL, open it anywhere, and paste back the code.

gcloud auth login --no-launch-browser

2Fix

Run init with --no-launch-browser, open the printed accounts.google.com URL in any trusted browser, sign in, and paste the authorization code at the prompt.

gcloud init --no-launch-browser

3Verify

gcloud lists the account as active.

gcloud auth list

Confirmed by docs.cloud.google.com

Did this fix it?

Cause 3 of 3

A script or server should not use a person's login at all

1Check

The docs recommend a service account for fully non-interactive use. Ask whether a person really needs to sign in here.

gcloud auth list

2Fix

Create a service account with only the roles the job needs, download its key once, and activate it.

gcloud auth activate-service-account --key-file=KEY_FILE.json

3Verify

The service account shows as the active account.

gcloud auth list

Confirmed by docs.cloud.google.com

Did this fix it?

How do I stop it coming back?

  • On WSL, SSH hosts and containers, start with the --no-browser flow instead of waiting for a window.
  • Use service accounts for automation and keep their keys out of repositories.
  • Run gcloud auth list after any sign-in to confirm which account is active.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.