50

Error message when using git push:

Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information. fatal: unable to access 'https://github.com/codingTheWorld777/react-mini-projects.git/': The requested URL returned error: 403"***

I cannot use my token to access GitHub, so how can I push code to GitHub?

Wouter
  • 534
  • 3
  • 14
  • 22
user16226729
  • 481
  • 1
  • 4
  • 6
  • though `git push` or some lib? besides, follow the link it, read the page it tells you what you need to do. tldr, see: https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token – Lawrence Cherone Aug 13 '21 at 23:53
  • When I use **git push** though. I added a picture in the description. – user16226729 Aug 13 '21 at 23:58
  • Yeah I have read the link but I am not sure that is my case. I have created a token and in the doc, I don't see anything that show me how to use token for git credential : – user16226729 Aug 14 '21 at 00:02
  • ok, follow the link above, basically, the token you create (instructions in the link) replaces the password value that you would normally enter ([ref](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token#using-a-token-on-the-command-line)). If your developing locally there should be no reason not to use public-key SSH, you only need add it once then you don't need to use usernames or passwords for any git action on any repo. – Lawrence Cherone Aug 14 '21 at 00:02
  • Gotcha. I just need to delete my github password in keychain in order to re-sign in to github credential :) . Anyway, thanks a lot! – user16226729 Aug 14 '21 at 00:09
  • Do you have not a public SSH key in your settings? If so, switch to SSH via git@github.com:/.git – astrochun Aug 14 '21 at 00:33
  • here is quick tutorial for mac https://youtu.be/iKf8-hhdWjs – VedantK Aug 20 '21 at 07:57

8 Answers8

50

GitHub announced their intent to require the use of token-based authentication for all authenticated Git operations. They will no longer accept account passwords when authenticating Git operations on GitHub.com:

Generate token:

On Mac:

  • Go to keychain Access
  • Press the Login tab and all items
  • Click GitHub key
  • Change the password to the recent generated token

Enter image description here

On Windows:

  • Go to Control PanelUser AccountsCredential Manager

  • Edit the Generic Credential of GitHub

  • Paste the token instead of the password

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ahmed Imam
  • 1,315
  • 2
  • 19
  • 42
  • Show man, running on mac with this tip – Flávio Aug 14 '21 at 12:43
  • 1
    Github not identifying this crucial step for Mac users in their documentation and/or error message is probably costing hundreds or thousands of developer hours. – Pigpocket Aug 14 '21 at 20:54
  • 2
    This is not a good solution for MacOS users. It replaces your login credentials for safari, and may break subsequent third party oauth links to your github account depending on token permissions. – Joshua Kolden Aug 16 '21 at 20:28
  • Hi @JoshuaKolden, thanks for that info, whats the good way to fix that for MacOS then ? – Ahmed Imam Aug 17 '21 at 00:58
  • @AhmedImam So far the only solution I can recommend is to use ssh auth and avoid the global account token altogether. Most answers that involve using token auth are significantly less secure (embedding your token in a world readable repo, `ps` visible command line arguments, bash history, etc) and higher maintenance effort. This is seriously the strangest security roll out I've ever seen. – Joshua Kolden Aug 17 '21 at 20:40
  • @JoshuaKolden I totally agree. @AhmedImam Your Mac OSX solution is wrong. You don't change "Internet Password" that's just for browser usage. You have to add an entry with `name=git:https://github.com`, `Kind=Programme password`, Account=your github username, `where=git:https://github.com`. The cleanest way to do this however is to `brew install gh` and then run `gh auth login`. This adds the **correct** entry into your keychain (cf. solution from @Niyaz). – Thomas Aug 18 '21 at 10:32
  • @Thomas I tried "brew install gh" and "gh auth login" as u recommended but it eventually change the "Internet Password" of github.com password to the token. can u please be more detailed or post your answer in the main question, this one already marked as duplicated, then provide the link here. – Ahmed Imam Aug 19 '21 at 04:36
  • @AhmedImam this solution has already been posted by **Niyaz**. I think his/her solution as **Joshua Kolden**'s solution are the correct ones. The above solution involving manually changing entries in keychains is not good or even reliable. – Thomas Aug 20 '21 at 10:23
  • @JoshuaKolden could you please post your solution so that people can use it/comment on it/evaluate it? – Thomas Aug 20 '21 at 10:24
  • 1
    @Thomas I can't because it's closed. – Joshua Kolden Aug 20 '21 at 18:27
24

You need to change the remote URL with:

git remote set-url <stream> https://<token>@github.com/<username>/<repo>

token can be found here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yuh Lee
  • 343
  • 1
  • 4
21

I also encounter this problem today, on macOS.

I solve this problem by:

First, get a token! Follow the guidance of GitHub. I think you can just click the link provided in the warning.

Second, change the key chain on macOS:

  1. Search "Keychain" on macOS.
  2. Search "GitHub".
  3. Change the password in the one that with "Internet Password", using your new token.

Then, my problem is solved and I can "git push" now.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
YanjieZe
  • 329
  • 1
  • 5
  • 1
    thanks, it helped. The other thing we need to take care of is to generate a token every time the token expires or we generate a token that never expires. – Samrat Aug 14 '21 at 06:23
  • Thx a lot! This is essentially the same as this answer here: https://stackoverflow.com/a/68776344/15250330 – Falaen Aug 14 '21 at 09:05
  • Change the password in the one that with "Internet Password", using your new token. did the trick for me – Ahmad Shahwaiz Aug 15 '21 at 10:15
  • i think may be go to github.com enter your credentials and save the info in keychain. then check – Ahmad Shahwaiz Aug 18 '21 at 09:20
  • @yanjieZe and @AhmadShahwaiz: Your Mac OSX solution is wrong. You do not need to change "Internet Password" that's just for browser usage (and has nothing to do with the OP). You have to add an entry with `name=git:https://github.com`, `Kind=Programme password`, Account=your github username, `where=git:https://github.com`. The cleanest way to do this however is to `brew install gh` and then run `gh auth login`. This adds the **correct** entry into your keychain (cf. @niyaz's solution). – Thomas Aug 18 '21 at 10:28
16

Step 1: Go to your GitHub account → SettingsDeveloper settingsPersonal access tokens → Generate / regenerate your token

Step 2: Go to https://cli.github.com and download GitHub CLI

Step 3: Go to your command line or Terminal → gh auth login and follow with login credentials. Done.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Niyaz
  • 733
  • 2
  • 8
  • 17
  • 1
    Only this worked for me. PAT generated ---> in keychain there is NO "Internet Password" entry!!! So I ran `brew install gh`, then executed the above command and chose the appropriate options (the PAT needs rights for `repo` + `workflow` + `admin:read:org`) then pasted in the PAT, and done. I can now call `git pull`, `git push`, _etc._ from bash. – Thomas Aug 18 '21 at 09:15
  • @Niyaz your answer is the only correct one so far for Mac OSX esp. regarding the OP. – Thomas Aug 18 '21 at 10:30
  • 1
    @Thomas, just tried out with Windows 10, seems working fine with the above steps, in Windows, Step 1: https://cli.github.com/ - CLI downloaded for windows Step 2: in Windows Terminal `gh auth login` once Logged in successful with username, then i could able to push the commits.. – Niyaz Aug 19 '21 at 09:46
  • brilliant! I was only able to say that your solution works under Mac OSX. But given that you've now checked on windows (I assume that bash for windows is installed?) then your solution is imo the cleanest and best. – Thomas Aug 20 '21 at 10:21
  • how do I make this gh interact with my local git installation? – Lokomotywa Apr 06 '22 at 10:31
10

I have the same problem. For me the solution was install the GitHub CLI in https://cli.github.com/. After installing in my OS, I ran gh auth login in my terminal and logged in through the browser with the access token that I generated in the GitHub profile. Follow:

My AccountSettingsDeveloper settingsPersonal access tokens [GENERATE NEW TOKEN]

yivi
  • 42,438
  • 18
  • 116
  • 138
  • 1
    Thanks : ) Only this worked for me. PAT generated ---> in mac osx keychain there is NO "Internet Password" entry!!! So I ran `brew install gh`, then executed the above command and chose the appropriate options (the PAT needs rights for `repo` + `workflow` + `admin:read:org`) then pasted in the PAT, and done. I can now call `git pull`, `git push`, _etc._ from bash. – Thomas Aug 18 '21 at 09:16
  • 1
    Only this solution worked on mac (Y) – Khateeb321 Mar 10 '22 at 15:14
5

First of all, you need to create a personal access token in Creating a personal access token

git clone https://github.com/username/repo.git

Username: your_username

Password: your_token
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • most people already know this and your answer does not address the main issue in the OP. The problem is _permanently_ setting the credentials, so that one can call `git pull` and `git push` from a bash terminal. – Thomas Aug 18 '21 at 09:18
1

Solution for Mac:

First generate a token from GitHub. And replace your password with the token from the keychain access in the GitHub section.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mir Mahfuz
  • 663
  • 4
  • 9
  • Your Mac OSX solution is plain **wrong**. You do not need to change "Internet Password" that's just for browser usage. You have to add an entry with `name=git:https://github.com`, `Kind=Programme password`, Account=your github username, `where=git:https://github.com`. But the cleanest way to do this however is to `brew install gh` and then run `gh auth login`. This adds the **correct** entry into your keychain (cf. @niyaz's solution). – Thomas Aug 18 '21 at 10:29
-1

You need to create a personal access token. You can find the instructions on creating personal access token in Creating a personal access token

Make sure you keep the access token secure & secret. After that you need to replace your current saved password in the device (laptop/desktop) with the access token. In macOS you can search for Keychain and find GitHub with an Internet password and replace it with your access token. For instructions, see Updating credentials from the macOS Keychain.

In Windows, it might be Credential Manager (I'm not sure). Check this out: How to update your Git credentials on Windows

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shanu
  • 169
  • 2
  • 10