Skip to content

How to

gh auth login opens the wrong browser profile? Fix the sign-in link

Updated

You run gh auth login or aws sso login, the browser opens, and you're in the wrong profile: signed in to your personal GitHub, or to no AWS account at all. The tool only asks your computer to open a link. Here's how to make it open in the right profile.

Why the sign-in page opens in the wrong profile

Command-line tools open their sign-in page in your default browser. The browser then picks the profile whose window you used last. If that's your personal profile, you approve the work tool with your personal account, or you have to sign in from scratch.

It's worse with several clients or AWS organizations, one profile each: the link has no idea which one you meant.

Any tool: open the link yourself

Most tools print the link as well as opening it. Close the wrong tab, copy the link from the terminal, and paste it into a window of the right profile. For aws sso login, stop the browser from opening at all:

aws sso login --profile acme-prod --no-browser

It prints the link to open. The sign-in finishes on your own computer, so it works from any profile.

GitHub CLI: choose the browser with GH_BROWSER

gh reads GH_BROWSER (or BROWSER) for the browser to open links in, and adds the link to the end of that command. To send its links to one Chrome profile on a Mac:

export GH_BROWSER='open -na "Google Chrome" --args --profile-directory="Profile 1"'

Find the profile's folder name, here Profile 1, in chrome://version under Profile Path. Put the line in your shell's startup file to keep it. This is one profile for every gh link, so it doesn't help if you switch between GitHub accounts.

Every tool: open sign-in links where you're signed in

Profile Porter treats sign-in links as a case of their own. When a tool's link starts a sign-in, such as GitHub's device page or an AWS, Google or Microsoft sign-in, it opens in the profile that's signed in to that provider.

  • If no profile is signed in, it asks rather than guess, and remembers your pick for sign-ins from that app.
  • If you were on the site in the last 15 minutes, the link goes to that profile.
  • No setup per tool: it looks at the link itself, so gh, aws and other tools that open a sign-in page are covered alike.

It reads where you're signed in from your browsers, on your computer, in Chrome, Edge, Brave, Arc, Firefox and Safari profiles.

Get Profile Porter for €12, once.

Everything included, no account, and a full refund within 14 days if it isn't for you. macOS 14 or later; on Windows 10 and 11, get it from the Microsoft Store.