Add function to account authentication without GUI
Another choice for large context model integrated coding tool , great !
However I tried in current setting I can't login in with my subscribed account on server without GUI, will U plan to fix it later?
This would be huge for me too
Yeah, currently gemini-cli tries to use xdg-open which requires GUI.
For now you can log in on a Windows machine and copy cached tokens from your local .gemini folder over to the Linux server you want to use them on.
Ty @sevosik
If you login with oauth, you can copy ~/.gemini/oauth_creds.json to login
If you login with oauth, you can copy ~/.gemini/oauth_creds.json to login
Thanks, this works.
This is a known limitation documented in authentication.md:
Note that the web login must be done in a browser that can communicate with the machine Gemini CLI is being run from. (Specifically, the browser will be redirected to a localhost url that Gemini CLI will be listening on).
We do plan on allowing this soon, however.
This is blocking Firebase Studio customers from being able to use the CLI in our code view. We'd really love it if this could be prioritized to unblock this in-browser terminal experience.
This is a known limitation documented in authentication.md:
Note that the web login must be done in a browser that can communicate with the machine Gemini CLI is being run from. (Specifically, the browser will be redirected to a localhost url that Gemini CLI will be listening on).
We do plan on allowing this soon, however.
This could use some clarification. The above is true when running in a devcontainer for example, but the error still happens.
This issue is a big deal. It's incredibly difficult to login right now on a linux server. I've spent the last 30 minutes trying to get it working with no success.
I was able to patch my way around this with the following:
Create an xdg-open stub that logs URLs instead and put it in $PATH
#!/bin/bash
# xdg-open stub installer for logging URLs instead of opening them
STUB_DIR="$HOME/xdg-stub"
LOG_FILE="$HOME/xdg-open-urls.log"
mkdir -p "$STUB_DIR"
cat > "$STUB_DIR/xdg-open" <<EOF
#!/bin/bash
echo "\$(date +'%Y-%m-%d %H:%M:%S') \$1" >> "$LOG_FILE"
exit 0
EOF
chmod +x "$STUB_DIR/xdg-open"
if [[ ":$PATH:" != *":$STUB_DIR:"* ]]; then
export PATH="$STUB_DIR:\$PATH"
echo "PATH modified. You may want to add this line to your shell profile:"
echo " export PATH=\"$STUB_DIR:\$PATH\""
fi
echo "Stub installed. URLs will be logged to: $LOG_FILE"
Run gemini-cli
$ npx https://github.com/google-gemini/gemini-cli
Attempt a Google account login in gemini-cli
You might need to run /auth to reselect
View the log file in a separate SSH session/tab and click the latest link
cat ~/xdg-open-urls.log
Log in to a Google account (make sure not to select a Workspace account)
You'll see an error from your browser since it can't connect to localhost - that's expected. Determine what port number it's trying to connect to from the URL bar, and note that down
Add an SSH port-forward for that port
Press Enter-Enter, then ~ then C in an SSH session and you'll drop to the SSH commandline
For me the port number was 45265, so let's use that:
Enter -L 45265:localhost:45265 then strike Enter twice
Reload the browser OAuth2 callback page, you're now logged in!
There is a timeout, so don't take too much time running through this. :)
I'm not sure why, but I'm getting connection failed: Connection refused on my tunnel logs and browser still shows ERR_CONNECTION_RESET
A quick workaround for those like me who dev in docker container (on your host), the quick workaround is to login once on you host
npx https://github.com/google-gemini/gemini-cli
then mount or copy your host ~/.gemini/ to your container.
For me it looks like this in my docker-compose:
services
dev-env:
build:
# ...
volumes:
# ...
- ~/.gemini:/root/.gemini # Gemini CLI cache persistence
@MUSTARDTIGERFPV In your Create an xdg-open stub that logs URLs instead and put it in $PATH step, change
export PATH="$STUB_DIR:\$PATH"
to
export PATH="$STUB_DIR:$PATH"
And then your script works for me. However, I'm still stuck on the "Waiting for auth..." screen.
I'm not sure why, but I'm getting connection failed: Connection refused on my tunnel logs and browser still shows ERR_CONNECTION_RESET
I had the same issue. I worked out that I was using the wrong url. I was using the localhost:xxxxx url instead of the https://accounts.google.com that gemini gave me. Once I used that (after doing ssh command), it worked.
I ran into this issue and just replaced the localhost part of the second URL with the IP of my headless server and the authentication went through.
Is there a plan to fix Gemini-cli so that workarounds are not necessary on headless or remote environments?
I was able to patch my way around this with the following:
Create an xdg-open stub that logs URLs instead and put it in $PATH
#!/bin/bash
xdg-open stub installer for logging URLs instead of opening them
STUB_DIR="$HOME/xdg-stub" LOG_FILE="$HOME/xdg-open-urls.log"
mkdir -p "$STUB_DIR"
cat > "$STUB_DIR/xdg-open" <<EOF #!/bin/bash echo "$(date +'%Y-%m-%d %H:%M:%S') $1" >> "$LOG_FILE" exit 0 EOF
chmod +x "$STUB_DIR/xdg-open"
if [[ ":$PATH:" != ":$STUB_DIR:" ]]; then export PATH="$STUB_DIR:$PATH" echo "PATH modified. You may want to add this line to your shell profile:" echo " export PATH="$STUB_DIR:$PATH"" fi
echo "Stub installed. URLs will be logged to: $LOG_FILE"
Run gemini-cli
$ npx https://github.com/google-gemini/gemini-cli
Attempt a Google account login in gemini-cli
You might need to run /auth to reselect
View the log file in a separate SSH session/tab and click the latest link
cat ~/xdg-open-urls.log
Log in to a Google account (make sure not to select a Workspace account)
You'll see an error from your browser since it can't connect to localhost - that's expected. Determine what port number it's trying to connect to from the URL bar, and note that down
Add an SSH port-forward for that port
Press Enter-Enter, then ~ then C in an SSH session and you'll drop to the SSH commandline For me the port number was 45265, so let's use that: Enter
-L 45265:localhost:45265then strike Enter twiceReload the browser OAuth2 callback page, you're now logged in!
There is a timeout, so don't take too much time running through this. :)
Thanks, this worked at my Linux Server, add the gemini api key on .bashrc