Github personal access token stops working after the first use

1k views Asked by At

I'm using a personal access token to access Github from the command line, in place of a password when prompted for my username and password. If I make a new access token, it works just fine in place of my password the first time, but if I try to use it again, I get this error:

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for <my-repo>

The only way I have been able to use Github from the command line has been to make a new personal access token every single time I need to use a password.

I have tried different expiration dates, but nothing seems to change this behavior. I also have experimented with the new fine-grained tokens, but I need to be able to access private repositories that I do not own (through Github classroom) and as far as I can tell the fine-grained tokens don't allow me to do that without being provided with a token by the admin, which isn't an option for me.

I have the same issue across multiple platforms, so I don't think it has to do with my local environment.

2

There are 2 answers

4
Martin Zeitler On

That PAT is being revoked for any reason and you can likely find the answer in the security log.

2
VonC On

It is possible your old password (not token) is currently stored in your credential helper:

git config --global credential.helper

If you get a value (say xxx), check what if your password is stored there:

printf "host=github.com\nprotocol=https" | git-credential-xxx get

If you see the old password, remove it, and store a new PAT (token).

printf "host=github.com\nprotocol=https\nusername=yourAccount" | git-credential-xxx erase

printf "host=github.com\nprotocol=https\nusername=yourAccount\npassword=yourToken" | git-credential-xxx store

For each commands, replace xxx by the value of the credential helper.