Skip to content

SSH device login can appear stuck when remote host opens a terminal browser #13445

Open

Description

@whiwoon

Describe the bug

When running gh auth login on a remote/headless-ish Linux host over SSH, choosing "Login with a web browser" can become confusing or appear stuck after the prompt:

! First copy your one-time code: XXXX-XXXX
- Press Enter to open github.com in your browser...

In this environment, pressing Enter attempted to open a browser on the remote Linux host rather than making it clear that the user can complete the device flow in a browser on their local machine. The remote host had terminal/browser alternatives installed, so the user saw browser-like content in the SSH terminal and attempted to continue there.

Meanwhile, entering the one-time code in the local Mac browser did not appear to make progress from the user's perspective. The login succeeded only after retrying with a no-op browser command:

GH_BROWSER=/bin/true gh auth login

With that workaround, gh did not open a remote terminal/browser UI and the normal device-code flow completed using the local Mac browser.

This seems closely related to the headless-machine UX discussed in #5500, but this case is a bit different: a browser command exists and may succeed by opening a terminal/browser UI on the remote host, even though that is not the browser the user expects when connected over SSH.

Affected version

gh version 2.92.0 (2026-04-28)
https://github.com/cli/cli/releases/tag/v2.92.0

Environment:

Linux wing 6.12.75+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.12.75-1+rpt1 (2026-03-11) aarch64 GNU/Linux
Debian GNU/Linux 13 (trixie)
Architecture: arm64

Browser-related commands/config detected on the host:

/usr/bin/xdg-open
/usr/bin/lynx
/usr/bin/www-browser
www-browser -> /usr/bin/lynx
x-www-browser alternative also configured

The user was connected from macOS to the Linux host via SSH and intended to complete device authentication in the macOS browser.

Steps to reproduce the behavior

  1. SSH from a desktop/laptop into a Linux host that has gh installed and has a terminal browser / browser alternative such as lynx, www-browser, or similar.
  2. Run gh auth login.
  3. Select GitHub.com, HTTPS, and "Login with a web browser".
  4. At Press Enter to open github.com in your browser..., press Enter.
  5. Observe that gh attempts to open a browser on the remote host / inside the SSH terminal, which is not the local desktop browser the user expects.
  6. Try entering the device code in the local desktop browser. From the user's perspective, the SSH terminal still appears stuck or focused on the remote browser flow.
  7. Retry with GH_BROWSER=/bin/true gh auth login; the flow completes successfully using the local browser.

Expected vs actual behavior

Expected:

  • For SSH/headless contexts, gh auth login should make it obvious that the user can manually open https://github.com/login/device on another machine/browser and enter the displayed code.
  • If a terminal browser is opened on the remote host, gh should not make the flow appear stuck or imply that this remote browser is the required path.
  • Ideally, there should be a clear documented/non-interactive way to say "do not open a browser; just print the URL/code and keep polling".

Actual:

  • Pressing Enter tried to open a browser on the remote host.
  • Because a terminal/browser alternative existed, the fallback did not simply fail and print manual instructions; it led the user into a confusing remote terminal-browser experience.
  • The successful workaround was to set GH_BROWSER=/bin/true so the browser-open step becomes a no-op while the device-code polling continues.

Logs

The successful workaround was:

GH_BROWSER=/bin/true gh auth login

After authentication:

github.com
  ✓ Logged in to github.com account whiwoon (.../.config/gh/hosts.yml)
  - Active account: true
  - Git operations protocol: https

Related prior discussion: #5500

Activity

  1. babakks commented on May 18, 2026

    @babakks
    Member

    Thanks for reporting this, @whiwoon! 🙏

    Anyway, this is a UX gap. The device flow technically works, but when a terminal browser like lynx is registered on the remote host, the experience becomes confusing because gh happily opens it inside the SSH session rather than signaling that you should use a browser on your local machine.

    Forcing the invocation to be non-interactive (e.g. gh auth login | cat) can be helpful since gh won't try to open the browser and will just print the URL. But the problem is there'll be no interactive prompting which is not nice.

    Related: #5500 (headless machine with no browser at all, which is a different scenario from yours where a browser exists but isn't the right one).


    I'm thinking of addressing this with two changes:

    1. A new --no-browser flag on gh auth login that suppresses the Browse() call entirely. You'd still get the full interactive experience (protocol selection, SSH key prompt, etc.) but gh would just print the URL for you to open manually on whatever machine you prefer. This is similar to how the non-interactive path already works today (which is why gh auth login | cat happens to work as a workaround, but you'll miss the interactive prompts).

    2. Best-effort SSH session detection (checking env vars like SSH_TTY). If detected, gh would print a hint on stderr suggesting --no-browser, without changing any default behavior. This keeps things non-breaking for users who genuinely want to open a browser on the remote host.

    @whiwoon, what do you think of this approach? Would --no-browser plus the SSH hint have resolved the confusion in your case?

  2. added
    enhancement
    more-info-needed
    gh-auth
    and removed
    more-info-needed
    on May 18, 2026
  3. github-actions commented on May 18, 2026

    @github-actions
    Contributor

    Thank you for your issue! We have categorized it as an enhancement (feature or improvement) request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.

    Unless you see the help wanted Contributions welcome label, we are not currently looking for external contributions for this feature.

    If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.

  4. added
    needs-triage
    and removed
    needs-triage
    on May 18, 2026
  5. removed
    needs-triage
    on May 18, 2026
  6. whiwoon commented on May 18, 2026

    @whiwoon
    Author

    Yes, I think --no-browser plus an SSH-session hint would have resolved the confusion in my case.

    The confusing part was that gh auth login opened lynx inside the SSH session, which made it feel like that was the expected path. I still wanted the normal interactive prompts; I just needed gh to print the URL so I could open it in a browser on my local machine.

    A best-effort hint when SSH_TTY is present sounds like the right non-breaking behavior to me, since some users may intentionally use a browser on the remote host.

    Thanks for taking a look at this!

  7. rbutleriii commented on Jul 29, 2026

    @rbutleriii
  8. nikelborm commented on Aug 21, 2026

    @nikelborm

    Another solution I found is that, instead of remembering to set this environment variable, you can permanently set it in the config with this command:

    gh config set browser /bin/true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgh-auth

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions