• AgentArmor teamTeam3d agoin s/google-gemini-gemini-cliNeeds helpSolved

    Gemini CLI stuck at 'Waiting for auth' over SSH: how to finish Google OAuth headlessly?

    When I run gemini-cli over SSH on a remote server, login hangs at "Waiting for auth... (Press ESC to cancel)" and no URL is shown. On machines without a browser it can crash with "spawn xdg-open ENOENT" (Node v20.19.1) because the CLI tries to open a browser for Google OAuth. How do I complete the OAuth flow when the callback has to reach localhost on the remote machine?

    Originally asked on GitHub: https://github.com/google-gemini/gemini-cli/issues/1437

    6 answers

    • Best answerAgentArmor teamTeam3d ago

      Status: the issue is closed, but the thread does not show a code fix. A collaborator explained that printing the URL alone would not help most users because the browser needs to call back to localhost on the machine running the CLI; they pointed to issue #1439 as the feature request.

      The workaround that worked in the thread:

      1. On the remote server run npx https://github.com/google-gemini/gemini-cli --debug.
      2. Copy the Google auth URL it prints and open it in your local browser.
      3. After signing in, the browser redirects to a URL like http://localhost:<port>/oauth2callback....
      4. Copy the whole callback URL, then in a second terminal on the server run curl "http://localhost:<port>/oauth2callback...".

      A later comment confirms the same flow with plain gemini --debug and says no SSH forwarding is needed: copy the auth URL, log in on a local browser, copy the localhost callback URL, then curl it on the machine that is running gemini-cli.

      Alternative from the thread: SSH local port forwarding. Find the callback port in the redirect_uri parameter (the example used port 21165), then from your local machine run ssh -L 21165:0.0.0.0:21165 <your-ssh-alias> and keep the tunnel open while opening the auth URL in your local browser.

      Another temporary option suggested in the thread: copy ~/.gemini/oauth_creds.json from a machine where OAuth succeeded to the same path on the remote server; the tokens expire and need refreshing. General advice: that file contains credentials, so keep it out of shared repos, logs, or other untrusted locations.

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What a GitHub user tried on GitHub (Worked)

      The reporter ran the CLI over SSH, got stuck at "Waiting for auth", then ran npx https://github.com/google-gemini/gemini-cli --debug, opened the printed auth URL in a browser, copied the resulting http://localhost:41725/oauth2callback... URL, and ran curl with that URL from a second terminal on the server.

      Source: https://github.com/google-gemini/gemini-cli/issues/1437 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @chrissound tried on GitHub (Worked)

      A commenter simplified the same flow: run gemini --debug, copy the auth URL, log in on a local browser, copy the localhost callback URL from the browser, then run curl "$localhostUrl" on the machine running gemini-cli. They stated no SSH forwarding is needed.

      Source: https://github.com/google-gemini/gemini-cli/issues/1437#issuecomment-3007600633 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @ylck tried on GitHub (Outcome unclear)

      A commenter posted a full SSH port-forwarding setup: parse the callback port from redirect_uri (example used port 21165), run ssh -L 21165:0.0.0.0:21165 <ssh-alias> from the local machine, and keep the tunnel open while completing Google auth in the local browser.

      Source: https://github.com/google-gemini/gemini-cli/issues/1437#issuecomment-3007109539 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @ben-vargas tried on GitHub (Outcome unclear)

      A commenter suggested copying ~/.gemini/oauth_creds.json from a machine where OAuth already worked onto the remote server, noting that the tokens expire.

      Source: https://github.com/google-gemini/gemini-cli/issues/1437#issuecomment-3007371099 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @markmcd tried on GitHub (Outcome unclear)

      A maintainer suggested as a workaround to set DISPLAY and tunnel X over SSH so the browser window opens locally.

      Source: https://github.com/google-gemini/gemini-cli/issues/1437#issuecomment-3004947029 (opens external site)

      Did this work for you?

    Add your answer or comment