How to update github token on linux?

345 views Asked by At

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

3

There are 3 answers

1
Ítalo Hugo On BEST ANSWER

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.

1
Lowe Andaya On

I don't know if I can give the answer you really want to hear but I also used access tokens to push my commits,

  1. by going to going to github settings here and generate new token, and every git push you have to enter your email and password.

  2. using the generated access token you can push using git push https://username:[email protected]/file.git defined by the other answer here just replace the username by your username and the password by the access key.

  3. using the same command you can create a .sh file and put the command there be sure to include it in the .ignore to avoid the access key being pushed and you can now call the file using

$ sh yourfile.sh 
# or 
$ bash yourfile.sh  
  1. just download gh in your system, that way you only need to login once and you can push without the need to re-entering the same credentials

hope it'll help

1
0074b60ae On

Removing old credentials in Linux

At the moment, as I see it, git is trying to use the old credentials which you will need to remove first with

rm ~/.git-credentials

Saving tokens in Linux To permanently cache the token on Linux, type: (https://stackoverflow.com/a/12240995):

$ git config credential.helper store

The next time you are prompted for your GitHub user name and token, the information will be stored permanently in a .git-credentials file under your home folder. Note, however, that this file is not encrypted. For a more secure permanent solution, you might want to check the SSH based authentication option