Use token to push some code to GitHub - "Support for password authentication was removed" [duplicate]
Asked Answered
C

8

53

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?

Colatitude answered 13/8, 2021 at 23:46 Comment(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: docs.github.com/en/github/authenticating-to-github/…Insurance
When I use git push though. I added a picture in the description.Colatitude
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 :<Colatitude
ok, follow the link above, basically, the token you create (instructions in the link) replaces the password value that you would normally enter (ref). 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.Insurance
Gotcha. I just need to delete my github password in keychain in order to re-sign in to github credential :) . Anyway, thanks a lot!Colatitude
Do you have not a public SSH key in your settings? If so, switch to SSH via [email protected]:<username>/<repo>.gitDachi
T
52

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

Tripitaka answered 14/8, 2021 at 5:23 Comment(10)
Show man, running on mac with this tipDamnedest
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.Dysphasia
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.Stricken
Hi @JoshuaKolden, thanks for that info, whats the good way to fix that for MacOS then ?Tripitaka
@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.Stricken
@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).Pemberton
@Pemberton 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.Tripitaka
@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.Pemberton
@JoshuaKolden could you please post your solution so that people can use it/comment on it/evaluate it?Pemberton
@Pemberton I can't because it's closed.Stricken
S
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.

Supersede answered 14/8, 2021 at 3:0 Comment(3)
What is stream? Can you please guide little about stream?Conversationalist
@Conversationalist Stream is a branching model. If you want to push code in master branch, the master will be your main stream.Squawk
I tried the same command by adding 'origin' or my origin name to set the URL for it.Conversationalist
S
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.

Sontich answered 14/8, 2021 at 2:54 Comment(5)
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.Zielinski
Thx a lot! This is essentially the same as this answer here: https://mcmap.net/q/45991/-github-change-from-password-to-personal-access-token-without-re-cloning-the-repoDyslogia
Change the password in the one that with "Internet Password", using your new token. did the trick for meWandy
i think may be go to github.com enter your credentials and save the info in keychain. then checkWandy
@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).Pemberton
N
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.

Nebraska answered 14/8, 2021 at 3:9 Comment(5)
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.Pemberton
@Nebraska your answer is the only correct one so far for Mac OSX esp. regarding the OP.Pemberton
@Thomas, just tried out with Windows 10, seems working fine with the above steps, in Windows, Step 1: 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..Nebraska
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.Pemberton
how do I make this gh interact with my local git installation?Floris
P
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]

Periclean answered 14/8, 2021 at 2:42 Comment(2)
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.Pemberton
Only this solution worked on mac (Y)Prizefight
P
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
Priddy answered 14/8, 2021 at 4:37 Comment(1)
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.Pemberton
T
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.

Titos answered 14/8, 2021 at 6:43 Comment(1)
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).Pemberton
I
-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

Icsh answered 14/8, 2021 at 2:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.