Skip to content

Document how to use personal access token in config file #286

Closed

Description

@johnandersen777

The client tries to open the browser to authenticate the user. However this doesn't work if you are on a remote system via ssh. Can the user generate a Personal Access Token and use that?

Activity

  1. tierninho commented on Jan 31, 2020

    @tierninho
    Contributor

    @pdxjohnny Thanks for the question.

    Yes, please use HTTPS and a person access token. If you need instructions for setting up the token, go here: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line

    Let us know how it goes.

  2. johnandersen777 commented on Jan 31, 2020

    @johnandersen777
    Author

    Where do I put the token, Is there a config file somewhere?

  3. johnandersen777 commented on Jan 31, 2020

    @johnandersen777
    Author

    I'm on Linux, I used git config --global credential.helper store and I can clone private repos without an access prompt. However gh still tries to open a browser to authenticate me.

  4. johnandersen777 commented on Jan 31, 2020

    @johnandersen777
    Author
  5. tierninho commented on Jan 31, 2020

    @tierninho
    Contributor

    Ah, great! Not too familiar with Linux! Cheers.

  6. changed the title [-]Can't authenticate without browser[/-] [+]Document how to use personal access token in config file[/+] on Jan 31, 2020
  7. johnandersen777 commented on Jan 31, 2020

    @johnandersen777
    Author

    It might be good to add this to the docs

  8. travi commented on Jan 31, 2020

    @travi

    is this tool compatible with a .netrc file?

  9. tierninho commented on Jan 31, 2020

    @tierninho
    Contributor

    Absolutely, just created an issue! #287

  10. tierninho commented on Jan 31, 2020

    @tierninho
    Contributor

    @travi Not sure about the compatibility. I suggest creating a new issue and a dev will circle back in due time. Perhaps give it a whirl and include the results? Thanks for the interest in gh.

  11. mislav commented on Feb 1, 2020

    @mislav
    Contributor

    @pdxjohnny Not that we don't really support Personal Access Tokens, as some commands might not work with that type of authentication; most notably the gh pr status command will yield a cryptic error

    graphql error: 'Field 'statusCheckRollup' doesn't exist on type 'Commit',
    Field 'reviewDecision' doesn't exist on type 'PullRequest''
    

    It's better to authenticate on a local machine using OAuth and then copy the resulting ~/.config/gh/config.yml file to the remote machine under SSH.

    @travi We don't yet respect the netrc file, but we appreciate the suggestion!

  12. johnandersen777 commented on Feb 1, 2020

    @johnandersen777
    Author

    @mislav Thank you! Great idea

  13. ggb667 commented on Oct 18, 2021

    @ggb667

    This [editing files] is horribly compex.
    < strikethrough >I'm on windows, no one knows or wants this. Just put passwords back.<\strikethrough>

  14. mislav commented on Oct 19, 2021

    @mislav
    Contributor

    @ggb667 Manually editing the config file is not something I'd recommend to most users, either. Generally, you can just run gh auth login and follow the browser-based authentication flow that's easy to perform on any platform. Alternatively, the same command will also accept a pasted Personal Access Token.

  15. ggb667 commented on Nov 6, 2021

    @ggb667

    I didn't know that you could just use the PAT as the password and it would work. The prompt should say Password or Personal Access Token to make it clear.

  16. rkulla commented on Dec 7, 2021

    @rkulla

    For anyone stumbling across this PR still via google, the github: section should go in hosts.yml not config.yml or you will probably get errors.

  17. mislav commented on Dec 7, 2021

    @mislav
    Contributor

    For anyone still wondering about how to use their Personal Access Token with GitHub CLI, the answer is to never edit the config files directly. Their location and format might change over time (as it already has since then). The solution is to use the gh auth login command, which can either generate a token for you (by taking you through the browser authorization flow) or take an already generated token as input.

  18. added a commit that references this issue on Jul 21, 2025
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions