Skip to content

Yubikey and/or other hardware authenticators #2176

Description

@Firehawke

Suggestion: This might be a little difficult to do effectively cross-platform, but you should support the use of Yubikeys (and/or other types of hardware authenticators; even Windows Hello, for that matter) for authenticating to Github when using the CLI tool. I can't think of much that I consider of higher security importance than development accounts, and the slight nuisance of having to touch the key for security is a worthwhile trade-off to make sure that the token that CLI uses isn't stolen and misused.

Activity

  1. Firehawke commented on Oct 12, 2020

    @Firehawke
    Author

    I did do a quick search for Yubikey and didn't see anything referencing it, so if I missed that this is a dupe, please accept my sincere apologies on the matter.

  2. mislav commented on Oct 13, 2020

    @mislav
    Contributor

    Hi, thank you for the recommendation!

    When the CLI tool first authenticates to GitHub, we open the web browser for you where you go through the typical GitHub authentication flow. If you've set up a Yubikey with your GitHub account, you will be prompted to touch the key during that flow.

    After that, an OAuth token is generated for CLI and saved in your ~/.config/gh/hosts.yml file. From that point onward, no explicit authentication is needed since cached credentials are used. Of course, storing this token in plain text isn't ideal, so we're aiming to support storing it in your system's Keychain in the future.

    Where in this flow did you imagine a Yubikey step to be added for extra security? Once per first authentication (GitHub web already supports this), or every time someone uses CLI?

  3. Firehawke commented on Oct 14, 2020

    @Firehawke
    Author

    I was thinking per-use in replacement for the cached credentials, at least as an option for those who have such an authenticator on their account.

  4. added
    authrelated to tokens, authentication state, or oauth
    and removed
    more-info-neededMore info needed from user/contributor
    on Oct 14, 2020
  5. added
    coreThis issue is not accepting PRs from outside contributors
    on Oct 22, 2020
  6. mpdude commented on Sep 24, 2025

    @mpdude

    If I understand correctly that would mean you could have short lived credentials, and also the token returned by gh auth token would only be valid for hours?

    After that, you'd need to have the security key plugged in and/or additionally touch it.

    So, nothing that could be exfiltrated from a developer machine that would be of use for more than a rather short period.

    In the wake of the recent Shai-Hulud events this sounds like a promising solution.

  7. kgn commented on Apr 5, 2026

    @kgn

    I have been looking into this as well because of the recent Axios and LiteLLM attacks. I was surprised to find how easy it is to exfiltrate the full OAuth token from Keychain on my Mac using the shell command security find-generic-password -s "gh:github.com" -w. I was hoping that there'd be a way to use my YubiKey to protect against this, but it seems like the gh cli currently has no way to protect against these types of exfiltration attacks?

    @mislav I am not a security/encryption expert, but poking around with Claude Code and the gh CLI source I wonder if the gh CLI could add FIDO2 challenge-response authentication:

    1. gh auth login --fido2 generates a FIDO2 credential on the YubiKey — the private key never leaves the hardware
    2. GitHub stores the corresponding public key
    3. On each API call (or session), GitHub sends a challenge, gh signs it using the YubiKey
    4. No token is stored locally — there is nothing to exfiltrate

    Even if an attacker has full access to the filesystem, they cannot authenticate without the physical YubiKey. Same security model as SSH ed25519-sk keys, extended to the GitHub API. This could be combined with SSH ControlMaster-style session caching (one YubiKey touch per N hours) so you don't have to touch the YubiKey for every API request.

  8. mpdude commented on Apr 10, 2026

    @mpdude

    Given that the gh CLI may be invoked multiple times e. g. from shell scripts, there is no such thing as a persistent "session", and having to touch the key for every single invocation or API call seems impractical.

    However, it would be a huge improvement already if the CLI could create and store in the filesystem a rather short-lived token, which is valid for hours only. Then, when it detectes that such a token has expired, it could be replaced by touching the Yubikey.

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

    authrelated to tokens, authentication state, or oauthcoreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions