You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Login with a web browser on headless machine #5500
coreThis issue is not accepting PRs from outside contributorsdiscussFeature changes that require discussion primarily among the GitHub CLI teamenhancementa request to improve CLIgh-authrelating to the gh auth command
Describe the feature or problem you’d like to solve
If I have no browser installed I should still be able to run gh auth login and select Login with a web browser as I can open the URL on another machine.
Proposed solution
$ gh auth login
? What account do you want to log into? GitHub.com
- Logging into github.com
? How would you like to authenticate? Login with a web browser
! First copy your one-time code: XXXX-XXXX
No browser detected, please visit following URL:
https://github.com/cli-auth
How will it benefit CLI and its users?
A lot of people use headless machines to do their work. This would make the login process simplier for those.
Additional context
The current status looks like this:
$ gh auth login
? What account do you want to log into? GitHub.com
- Logging into github.com
? How would you like to authenticate? Login with a web browser
! First copy your one-time code: 36A4-6DE3
- Press Enter to open github.com in your browser...
/usr/bin/xdg-open: line 871: www-browser: command not found
/usr/bin/xdg-open: line 871: links2: command not found
/usr/bin/xdg-open: line 871: elinks: command not found
/usr/bin/xdg-open: line 871: links: command not found
/usr/bin/xdg-open: line 871: lynx: command not found
Reacted by Qays H. Poonawala, callumfrederiksen, Christoph Müllner, Ralf Vogler, Adam Hawley, Arthur Yidi, Reilly Wood, Kuno Woudt, Spenser Black, Mateen Ulhaq and 3 more
Hi, if xdg-open returns a nonzero exit status upon failure (as it should), then that will trigger this error condition in gh, and it will print the URL so you can open it on any computer with a web browser:
The BROWSER=false parameter works for me but it's not very straightforward. The output looks like:
$ BROWSER=false gh auth login
? What account do you want to log into? GitHub.com
- Logging into github.com
? How would you like to authenticate? Login with a web browser
! First copy your one-time code: C22A-D9BC
- Press Enter to open github.com in your browser...
! Failed opening a web browser at https://github.com/login/device
exit status 1
Please try entering the URL in your browser manually
The xdg-open 'http://github.com/' command will open the page in w3m web browser for me.
I use this machine mainly in headless mode via SSH but it has basic graphical environment installed as well.
What about modifying the dialog by adding third option? So it would look like:
$ gh auth login
? What account do you want to log into? GitHub.com
- Logging into github.com
? How would you like to authenticate? [Use arrows to move, type to filter]
> Login with a web browser
Login with an external web browser
Paste an authentication token
Reacted by Mislav Marohnić, callumfrederiksen, Geoffrey Martin-Noble, Reilly Wood, Kyle Awayan, 神楽坂アイリス and Markus Alexander Kuppe
Alternatively, could we always print the target URL https://github.com/login/device when opening in a web browser? So maybe a less-clunky version of the below:
! First copy your one-time code: C22A-D9BC
- Press Enter to open github.com in your browser,
or manually go to https://github.com/login/device
Reacted by Pavel Dostál, Sorin Sbarnea, callumfrederiksen, Ralf Vogler, Geoffrey Martin-Noble, Elan Hasson, Jesper van den Ende, Valentin Hilbig, Cameron Elliott, Anders Pearson and 16 more
@pdostal I like your proposal. I would reword the options to be more clear about where the browser in question runs:
? How would you like to authenticate? [Use arrows to move, type to filter]
> Login with a web browser on this machine
Login with a web browser on a different machine
Paste an authentication token
@rpadaki That's also an interesting idea, but I'm gravitating to the above flow because it requires more explicit intention from the user.
Reacted by Pavel Dostál, Nuno Agostinho, Arthur Yidi, Jesse Katsumata and David Ishmael
As long the full url is displayed we should be fine. IMHO, even Press Enter to open https://github.com/login/device in your browser would suffice.
No need to be too smart (detect) about it as long the message is smart-enough to allow the user to go manual.
Reacted by Pavel Dostál, Øystein Johnsen, Anders Pearson, Ralf Vogler, Kuno Woudt, Boran Gögetap, Nolan Amy and zachs18
I think that this is something that GitHub themselves may have to address since they are the ones hosting the site.
However, doing something like this may work using an api to an external web browser accessible on any device. This could potentially be done through the use of HTTP[S] GET/POST requests if executed in the right manner with security issues in mind if directly linked to an account.
Or you could do a command line login and not JUST an auth token?
This is also broken for me. My default browser is Chrome on Ubuntu, and I have multiple Chrome profiles. It pops open a profile selector, but the URL doesn't actually load after selecting a profile.
You could always try to make your tool with as many configurations as possible. In any case, I'd be happy if the tool printed the URL, and I sent you a PR for that (it's literally a one-line change). That would also help with some of the use cases above.
Reacted by Jesper van den Ende, Valentin Hilbig and zachs18
Did that not happen to you? Can you check the exit status of xdg-open and see if you're running an up-to-date GitHub CLI?
This doesn't work for everyone. I use the desktop environment when I'm at the machine, and ssh when I am not there.
I therefore never hit the failure scenario.
Why can't we just output the link ahead of time as suggested here: #5500 (comment)
Also, even when I do goto the URL manually and enter the code, gh hangs and doesn't ever acknowledge the code was entered. There is a bug here where a separate goroutine should be waiting for the code and cancel the other one that failed to launch the browser.
I love a great developer experience, however this endless bike shedding isn't fun.
> gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser
! First copy your one-time code: ABC-123F
Press Enter to open github.com in your browser...
[20013:20013:0612/204112.489039:ERROR:ozone_platform_x11.cc(239)] Missing X server or $DISPLAY
[20013:20013:0612/204112.489167:ERROR:env.cc(255)] The platform failed to initialize. Exiting.
Come on, its over a year now for such a simple thing!
This problem here hits me so often, that I already add a mandatory bookmark to https://github.com/login/device in all of my browsers which I use to login to GH. I nearly dare to request Firefox Sync to be taken out of the disallowed browser applications at my side due to this only issue with GH to get the bookmarks synced, because it is extremely annoying that the URL is not printed at all and I always have to type that in or add the bookmark manually.
If the URL would be printed into the terminal, it is just a single click to open the real local correct browser (terminology anyone?), because the local terminal always knows the right browser, but the deeply buried bash on the remote ssh session does not. Also it does not help if xdg-open opens a browser on the remote display (greetings from dbus), which then isn't logged into GH (if you happen to see the remote display at all, not all systems have x11vnc installed).
And if you are on it, please explain how to revoke the apropriate CLI again via web. Without access to the CLI.
But this is clumsy, as this revokes access for all CLIs alltogether!
Is there a way to individually remove a single CLI?
Note that gh auth logout does not log out other CLIs, only the local one. What if you want to remove all others but the current one?
No, this is NOT a request to add this feature (as this would be a new issue) but, if you are on it, please add the URL to the reverse, too!. This could go into the same line ..
Reacted by Ralf Vogler, David Wales and Mateen Ulhaq
I have not been able to resolve this. I work on a remote machine and can log in via remote desktop but this is extremely annoying. Why can I not authenticate on the CLI with my token? Reading the above comments I managed to get a browser open with w3m but after entering the one-time code I have to authorize GitHub to access data from my organisation (I don't know why I am asked every time) and then it fails because apparently JavaScript needs to work for that.
Not everyone has full administrative control over their computers. I am in a corporate environment and have now spent several hours already fiddling around with authentication on remote servers. Also VSCode with ssh connection is not able to authenticate GitHub copilot properly.
Note: I encounter this issue in WSL if I have curses-based browsers installed such as links or lynx. If I uninstall these, then update-alternatives sets the www-browser to wslview, which automatically opens URLs in the default Windows browser.
So, on WSL at least, you should be able to work around this problem with the following:
Note: I encounter this issue in WSL if I have curses-based browsers installed such as links or lynx. If I uninstall these, then update-alternatives sets the www-browser to wslview, which automatically opens URLs in the default Windows browser.
So, on WSL at least, you should be able to work around this problem with the following:
coreThis issue is not accepting PRs from outside contributorsdiscussFeature changes that require discussion primarily among the GitHub CLI teamenhancementa request to improve CLIgh-authrelating to the gh auth command
Activity
mislav commentedon Apr 22, 2022
Hi, if
xdg-openreturns a nonzero exit status upon failure (as it should), then that will trigger this error condition in gh, and it will print the URL so you can open it on any computer with a web browser:cli/internal/authflow/flow.go
Lines 95 to 99 in eb08a9b
Did that not happen to you? Can you check the exit status of
xdg-openand see if you're running an up-to-date GitHub CLI?You can also try setting
BROWSER=false gh auth loginto make it known that this is a headless environment.pdostal commentedon Apr 23, 2022
The
BROWSER=falseparameter works for me but it's not very straightforward. The output looks like:The
xdg-open 'http://github.com/'command will open the page inw3mweb browser for me.I use this machine mainly in headless mode via SSH but it has basic graphical environment installed as well.
What about modifying the dialog by adding third option? So it would look like:
rpadaki commentedon Apr 30, 2022
Alternatively, could we always print the target URL
https://github.com/login/devicewhen opening in a web browser? So maybe a less-clunky version of the below:! First copy your one-time code: C22A-D9BC - Press Enter to open github.com in your browser, or manually go to https://github.com/login/devicemislav commentedon May 4, 2022
@pdostal I like your proposal. I would reword the options to be more clear about where the browser in question runs:
@rpadaki That's also an interesting idea, but I'm gravitating to the above flow because it requires more explicit intention from the user.
ssbarnea commentedon Jun 21, 2022
As long the full url is displayed we should be fine. IMHO, even
Press Enter to open https://github.com/login/device in your browserwould suffice.No need to be too smart (detect) about it as long the message is smart-enough to allow the user to go manual.
callumfrederiksen commentedon Jul 5, 2022
I think that this is something that GitHub themselves may have to address since they are the ones hosting the site.
However, doing something like this may work using an api to an external web browser accessible on any device. This could potentially be done through the use of HTTP[S] GET/POST requests if executed in the right manner with security issues in mind if directly linked to an account.
Or you could do a command line login and not JUST an auth token?
ulfjack commentedon Mar 6, 2023
This is also broken for me. My default browser is Chrome on Ubuntu, and I have multiple Chrome profiles. It pops open a profile selector, but the URL doesn't actually load after selecting a profile.
mislav commentedon Mar 7, 2023
That sounds like a problem with your browser, and not something that our tool should necessarily solve?
You could always try passing additional Chrome parameters in GH_BROWSER:
To find out your profile name, I think you can determine that by opening the
chrome://versionURL.ulfjack commentedon Mar 7, 2023
You could always try to make your tool with as many configurations as possible. In any case, I'd be happy if the tool printed the URL, and I sent you a PR for that (it's literally a one-line change). That would also help with some of the use cases above.
ElanHasson commentedon Jun 13, 2023
This doesn't work for everyone. I use the desktop environment when I'm at the machine, and ssh when I am not there.
I therefore never hit the failure scenario.
Why can't we just output the link ahead of time as suggested here: #5500 (comment)
Also, even when I do goto the URL manually and enter the code,
ghhangs and doesn't ever acknowledge the code was entered. There is a bug here where a separate goroutine should be waiting for the code and cancel the other one that failed to launch the browser.I love a great developer experience, however this endless bike shedding isn't fun.
hilbix commentedon Jul 26, 2023
Come on, its over a year now for such a simple thing!
This problem here hits me so often, that I already add a mandatory bookmark to https://github.com/login/device in all of my browsers which I use to login to GH. I nearly dare to request Firefox Sync to be taken out of the disallowed browser applications at my side due to this only issue with GH to get the bookmarks synced, because it is extremely annoying that the URL is not printed at all and I always have to type that in or add the bookmark manually.
If the URL would be printed into the terminal, it is just a single click to open the real local correct browser (
terminologyanyone?), because the local terminal always knows the right browser, but the deeply buriedbashon the remote ssh session does not. Also it does not help ifxdg-openopens a browser on the remote display (greetings fromdbus), which then isn't logged into GH (if you happen to see the remote display at all, not all systems havex11vncinstalled).And if you are on it, please explain how to revoke the apropriate CLI again via web. Without access to the CLI.
AFAICS the inverse is https://github.com/settings/applications and remove the entire GitHub Cli.
But this is clumsy, as this revokes access for all CLIs alltogether!
Is there a way to individually remove a single CLI?
Note that
gh auth logoutdoes not log out other CLIs, only the local one. What if you want to remove all others but the current one?No, this is NOT a request to add this feature (as this would be a new issue) but, if you are on it, please add the URL to the reverse, too!. This could go into the same line ..
FloHu commentedon Jun 21, 2024
I have not been able to resolve this. I work on a remote machine and can log in via remote desktop but this is extremely annoying. Why can I not authenticate on the CLI with my token? Reading the above comments I managed to get a browser open with w3m but after entering the one-time code I have to authorize GitHub to access data from my organisation (I don't know why I am asked every time) and then it fails because apparently JavaScript needs to work for that.
Not everyone has full administrative control over their computers. I am in a corporate environment and have now spent several hours already fiddling around with authentication on remote servers. Also VSCode with ssh connection is not able to authenticate GitHub copilot properly.
daviewales commentedon Jul 19, 2024
Note: I encounter this issue in WSL if I have curses-based browsers installed such as
linksorlynx. If I uninstall these, thenupdate-alternativessets thewww-browsertowslview, which automatically opens URLs in the default Windows browser.So, on WSL at least, you should be able to work around this problem with the following:
evilhamsterman commentedon Jul 19, 2024
You have to ensure the
wslupackage is installed to get the wslview apphttps://github.com/cli/cli/issues/5500
Karinza38 commentedon Oct 24, 2024
#5500 (comment)
corneliusroemer commentedon Sep 22, 2025
I've turned this into a StackOverflow Q&A for better discoverability and faster consumption: https://stackoverflow.com/questions/78890002/how-to-do-gh-auth-login-when-run-in-headless-mode/78890003#78890003
6A31 commentedon Mar 10, 2026
if
BROWSER=false gh auth loginstill shows same failing behaviour,GH_BROWSER=false gh auth logincan be used.