Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Personal Access Token not working on Linux

I am using Git on Linux. I followed this to create a Personal Access Token but forgot to save it. Therefore, when I was asked to enter the "password" again, I deleted the old PAT and created a new PAT. For some reason, the new token is rejected and I get

fatal: Authentication failed for 'https://github.com/username/***.git/'

When I look at the tokens page on github, this token says it was never used. What might be the issue here?

like image 517
user15988 Avatar asked Jul 28 '26 21:07

user15988


1 Answers

The issue might be with your current credential helper.

Type git config credential.helper to see which one is used.

Type:

printf "protocol=https\nhost=github.com"|git-credential-xxx erase

(Replace xxx by the credential helper name from the first command output)

That will clear out the cached credentials for https://github.com.

Then try again a git push, and see if it asks you for your credentials: enter your new PAT as password.

If you don't have a credential helper, I suggest installing microsoft/Git-Credential-Manager-Core (there is a Linux package).
Add a credential store, and you are set.


After discussion:

  • there was no credential helper
  • this is a personnal account (not a technical service one, used by multiple users)
  • the issue was with pasting the token

I would therefore use a store credential caching:

git config --global credential.helper 'store --file /home/<user>/.my-credentials

Then:

git ls-remote https://github.com/<user>/<repo>

That will trigger the prompt for your username and token.

Edit /home/<user>/.my-credentials and make sure the right token is in it.


Alternatively,

git config --global credential.helper 'store --file /home/<user>/.my-credentials'

and then:

git ls-remote https://<user>:<token>@github.com/<user>/<repo>

has worked.

like image 123
VonC Avatar answered Jul 30 '26 15:07

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!