gcloud init cannot finish the sign-in step
Error while trying to authenticate with gcloud initShort 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.
Fix it fast
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 login2Match what you see, then jump to its fix
- 1
The sign-in tab never opens, or the command waits forever.No browser can be opened on this machine, but another machine has gcloudFix - 2
You 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
The 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
- 1
What does the error look like?
Error while trying to authenticate with gcloud initEnter authorization codeEnter 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 version2Fix
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 listConfirmed by docs.cloud.google.com
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-browser2Fix
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-browser3Verify
gcloud lists the account as active.
gcloud auth listConfirmed by docs.cloud.google.com
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 list2Fix
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.json3Verify
The service account shows as the active account.
gcloud auth listConfirmed by docs.cloud.google.com
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
Security
AuthenticationException: your certificate validation callback returned false
System.Security.Authentication.AuthenticationException
This message means a validation callback was installed, yours or one a library added, and it returned false.
3 causes, each with a fixSecurity
SSH to an EC2 instance fails with Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
ec2-user@ec2-203-0-113-25.compute-1.amazonaws.com: Permission denied (publickey).
On EC2 this error almost always means the instance did not accept your key for that user.
3 causes, each with a fixSecurity
A GitHub Actions SSH deploy step cannot log in to the server
ssh: handshake failed: ssh: unable to authenticate
The runner reached your server but the server refused the login.
4 causes, each with a fixSecurity
SSH to GitHub asks to confirm the host, or hangs on that prompt
ED25519 key fingerprint is SHA256:
SSH has never seen github.com from this machine, so it asks you to trust the server key.
2 causes, each with a fixSecurity
A GUI program over SSH says it cannot open the display
cannot open display:
ssh must forward X11 and the remote sshd must allow it.
3 causes, each with a fixSecurity
PHP LDAP in Laravel fails with Can't contact LDAP server over TLS
unable to get local issuer certificate
PHP's LDAP client uses OpenLDAP's settings.
3 causes, each with a fix