Search code examples
linuxauthenticationgithubaccess-tokengithub-token

How to update github token on linux?


I was trying to push some files to my git repository, but I was receiving:

fatal: Authentication failed error.

Recently my access token was updated and I think that may be the cause of the problem. I've looked everywhere on how to update my access token on the Linux's terminal environment but haven't found anything, most indications only talk about MacOS or Windows.

I would like to know how to update this new access token for GitHub on Linux terminal?

I've tried following the authenticating steps on the official GitHub page, but that was not exactly what I was looking for.

GitHub's authentication guide:

https://mgimond.github.io/Colby-summer-git-workshop-2021/authenticating-with-github.html


Solution

  • To update GitHub's key access token you need to make sure you have GitHub's CLI (Command Line Interface) installed. You can do that by typing on a Linux's terminal:

    gh --help
    

    If you have it installed, it will display the CLI's help menu.

    You can proceed by typing:

    gh auth
    

    This will display the authentications actions you can do, which include login, logout, token (which will display the current token in use), and refresh, which will allow you to update your authentication's credentials, including you access token.

    To update the token type:

    sudo gh auth refresh
    

    The command line will display a code and will ask you to enter this code into a web browser instance, follow the steps and you credentials will be refreshed on the system.

    Alternatively, you can enter:

    sudo gh auth login
    

    This process will make you login your credentials manually through the terminal. At the end, it will ask you for a token and you can update it just by copying and pasting the your new access token.