gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Login with Google - Doesn't support (SSH Issue?) for headless login

Open JohnDotOwl opened this issue 1 year ago • 49 comments

It's stuck at ⠙ Waiting for auth... (Press ESC to cancel) , shouldn't it provide a url for me to authenticate?

For context, i'm doing SSH into my server so this isn't my computer


Update - Temporary solution Execute npx https://github.com/google-gemini/gemini-cli --debug

Proceed to accept and signin on browser via the provided link , you will receive a call back that looks like this on browser http://localhost:41725/oauth2callbac

Open another terminal , connect & copy the whole URL and do this

curl "http://localhost:41725/oauth2callbac...."

Get started coding and cancel your claude code subscription 😂

JohnDotOwl avatar Jun 25 '25 14:06 JohnDotOwl

Valid - the tool will open a browser window, so for SSH you may need to set DISPLAY and tunnel X as a workaround, but we should fix this to display the URL.

markmcd avatar Jun 25 '25 14:06 markmcd

Same question, it automatically opens the browser, but when I click log in, it crashes, and the webpage goes to this.

Image

kunls avatar Jun 25 '25 14:06 kunls

Gemini-CLI crashed:

node:events:502 throw er; // Unhandled 'error' event ^

Error: spawn xdg-open ENOENT at ChildProcess._handle.onexit (node:internal/child_process:285:19) at onErrorNT (node:internal/child_process:483:16) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) Emitted 'error' event on ChildProcess instance at: at ChildProcess._handle.onexit (node:internal/child_process:291:12) at onErrorNT (node:internal/child_process:483:16) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { errno: -2, code: 'ENOENT', syscall: 'spawn xdg-open', path: 'xdg-open', spawnargs: [ 'https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=REMOVED' ] }

Node.js v20.19.1

brianlkurtz avatar Jun 25 '25 14:06 brianlkurtz

Same question, it automatically opens the browser, but when I click log in, it crashes, and the webpage goes to this.

Image

Url add %2F

Image

zhmok avatar Jun 25 '25 14:06 zhmok

I have the same issue. @scidomino thanks for closing my issue, wasn't aware this is technically the same thing.

leninnava avatar Jun 25 '25 15:06 leninnava

Same question, it automatically opens the browser, but when I click log in, it crashes, and the webpage goes to this. Image

Url add %2F

Image

I think the that url should be correct https://github.com/google-gemini/gemini-cli/blob/21cfe9f6801f286dda6d51d2886e27bd67bd5fa4/packages/core/src/code_assist/oauth2.ts#L95


but also think if we can have the url in terminal and auth by ourselves would be great, then gemini cli can install in remote machine that don't have GUI, but no sure is there any other concerns

timching avatar Jun 25 '25 15:06 timching

not sure if this is a gui issue, when running under icewm, no browser window is popping up.

linzack avatar Jun 25 '25 15:06 linzack

To be clear, for most users who can't auth, displaying the url would not help since the browser needs to be able to contact Gemini CLI using localhost. See this https://github.com/google-gemini/gemini-cli/issues/1439 for the feature request.

scidomino avatar Jun 25 '25 16:06 scidomino

Having same issue

coulterj avatar Jun 25 '25 21:06 coulterj


Solving Google Code Assist Authentication on Remote Machines

When you're connected to a remote server via SSH and trying to authenticate Google Code Assist (e.g., by running gemini --debug), if the authentication requires a callback to localhost, you'll need to use SSH Port Forwarding.


Step 1: Obtain the Authentication URL and Callback Port

  1. Run gemini --debug on your remote server.
  2. Locate the authentication URL in the output, which will look something like https://accounts.google.com/o/oauth2/v2/auth?XXXXXXXXXXX.
  3. Copy this URL.
  4. Parse the redirect_uri parameter to identify the port number after localhost. For example, if redirect_uri is http://localhost%3A21165%2Foauth2callback, the port is 21165.

Step 2: Establish SSH Local Port Forwarding

On your local machine's terminal, execute the following command:

ssh -L 21165:0.0.0.0:21165 tk
  • 21165 (first instance): This is the port on your local machine that will listen for the callback.
  • 0.0.0.0: This is the remote server's address, pointing to the remote server itself.
  • 21165 (second instance): This is the port on the remote server, which must match the callback port you identified.
  • tk: This is your SSH alias or the remote server's address (e.g., user@your_remote_server_ip).

Keep this SSH connection active; do not close the terminal window.


Step 3: Complete Authentication

  1. Open the full authentication URL from Step 1 in your local machine's web browser.
  2. Complete the Google authentication process.

The authorization code will be forwarded through the SSH tunnel to the gemini client on your remote server, completing the authentication.

Once authentication is complete, you can close the SSH connection.

ylck avatar Jun 26 '25 05:06 ylck

To be clear, for most users who can't auth, displaying the url would not help since the browser needs to be able to contact Gemini CLI using localhost. See this #1439 for the feature request.

No, it would help if they provide a url and the web page provides a way to copy the auth token so we can copy and paste it back into the SSH session (i.e. like claude code OAuth). There should be a way to run this OAuth process without having to port forward over ssh - typically by presenting a URL and then asking for auth token to be pasted back in.

Another quick (but temporary) workaround is to simply copy the ~/.gemini/oauth_creds.json from a local machine where OAuth succeeds into your remote server. It will expire in due time though.

ben-vargas avatar Jun 26 '25 06:06 ben-vargas

Building upon @ylck 's solution (thank you). It's actually a lot simpler, no SSH forwarding needed.

  1. Run gemini --debug, copy the URL and open it in your browser
  2. Login via google auth
  3. Copy and paste the localhost URL
  4. "curl $localhostUrl" on the machine where you ran gemini --debug

chrissound avatar Jun 26 '25 08:06 chrissound

Temporary solution

Execute npx https://github.com/google-gemini/gemini-cli --debug

Proceed to accept and signin on browser via the provided link , you will receive a call back that looks like this on browser http://localhost:41725/oauth2callbac

Open another terminal , connect & copy the whole URL and do this

curl "http://localhost:41725/oauth2callbac...."

Get started coding and cancel your claude code subscription 😂

JohnDotOwl avatar Jun 26 '25 08:06 JohnDotOwl

Temporary solution

Execute npx https://github.com/google-gemini/gemini-cli --debug

Proceed to accept and signin on browser via the provided link , you will receive a call back that looks like this on browser http://localhost:41725/oauth2callbac

Open another terminal , connect & copy the whole URL and do this

curl "http://localhost:41725/oauth2callbac...."

Get started coding and cancel your claude code subscription 😂

it's work !!! thank you very much

flufy3d avatar Jun 26 '25 10:06 flufy3d

Come one guys.... If you promote a CLI tool you SHOULD know there is no breakout to a "graphic world" like X11 or Wayland! You have to present a url and give a token back which can be used in a kind of configuration file for the agent. The URL itsself should be run on any independent device. You can't expect a ssh forward or other tunnel staff like that! This sounds to me like a rookie.

Akusari avatar Jun 26 '25 17:06 Akusari

Facing a similar issue here. I'm not sure this would be an issue, because I already have a previously set up Vertex API key, but the web authentication seems to be the only way to use the free API calls?

Please correct me if I'm incorrect re: free API calls.

josephleblanc avatar Jun 26 '25 20:06 josephleblanc

Pretty big problem for a CLI app if it can't run on a server without a browser installed. Just use a token I can copy and paste rather than sketchy localhost communication from a browser.

robsmith11 avatar Jun 27 '25 05:06 robsmith11

If you can't/don't want to deal with ssh forward, this is simpler work around. You do need access to a browser to authenticate with your account though, but not on the headless server.

  • run gemini --debug. (--debug will output the authentication url)
  • Select "Login with Google"
  • You will get an output with a url for authentication (starting with https://accounts.google.com/o/oauth2). Open this url in a browser (on another machine that has a GUI, preferably).
  • Login with your account.
  • After login, you will be redirected to a localhost address. Copy and paste this.
  • In a new terminal on the headless machine, run: curl 'your_localhost_url'. Important to enclose the url in quotes, otherwise it will fail to parse.
  • Back in the gemini cli, you should now have successfully authenticated.

For me this is fine as a workaround, since it only has to be done once.

Rydberg95 avatar Jun 27 '25 06:06 Rydberg95

Even with --debug, it still crashes:

~ --debug                                                         no sandbox (see /docs)                                                            gemini-2.5-pro (100% context left)| 164.9 MB

node:events:495
      throw er; // Unhandled 'error' event
      ^

Error: spawn xdg-open ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:284:19)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:290:12)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn xdg-open',
  path: 'xdg-open',
...

robsmith11 avatar Jun 27 '25 07:06 robsmith11

If you can't/don't want to deal with ssh forward, this is simpler work around. You do need access to a browser to authenticate with your account though, but not on the headless server.如果您不能/不想向前处理 ssh,这是更简单的解决方法。不过,您确实需要访问浏览器才能对您的帐户进行身份验证,但不是在无头服务器上。

* run `gemini --debug`. (--debug will output the authentication url)运行 `gemini --debug` . (--debug 会输出认证 url)

* Select "Login with Google"选择“使用 Google 登录”

* You will get an output with a url for authentication (starting with `https://accounts.google.com/o/oauth2`). Open this url in a browser (on another machine that has a GUI, preferably).您将获得一个带有用于身份验证的 url 的输出(从 `https://accounts.google.com/o/oauth2` 开始)。在浏览器中打开此 url(最好在另一台具有 GUI 的机器上)。

* Login with your account.使用您的帐户登录。

* After login, you will be redirected to a `localhost` address. Copy and paste this.登录后,您将被重定向到 `localhost` 地址。复制并粘贴它。

* In a new terminal on the headless machine, run: `curl 'your_localhost_url'`. Important to enclose the url in quotes, otherwise it will fail to parse.在无头机器上的新终端中,运行: `curl 'your_localhost_url'` 。重要的是将 url 括在引号中,否则将无法解析。

* Back in the gemini cli, you should now have successfully authenticated.回到双子座 cli,您现在应该已经成功进行了身份验证。

For me this is fine as a workaround, since it only has to be done once.对我来说,这是一个很好的解决方法,因为它只需要做一次。

Works. Thank you!

retaw106 avatar Jun 27 '25 09:06 retaw106