GitHub keep asking for username password when git push

git clone one of my existing repo (with SSH key added in the Github), modified some files and tried to git push, and it keeps asking for username and password for git push operation?

Terminal

git push

Username for 'https://github.com':
Password for 'https://github.com':  

GitHub authentication is successful.

Terminal

ssh -T [email protected]           

Hi mkyong! You've successfully authenticated, but GitHub does not provide shell access.

1. Password authentication was removed

Even if we enter the correct username and password, Github still does not allow for pushing because the password authentication was removed on August 13, 2021. Please use a personal access token instead.

Terminal

% git push     

Username for 'https://github.com': [email protected]
Password for 'https://[email protected]@github.com':
remote: 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: Authentication failed for 'https://github.com/mkyong/spring-boot/'

2. Use SSH, not HTTPS

The main reason for this problem is mistakenly git clone the HTTPS URL; we need the SSH URL to use the SSH keys. The solution is to update the .git/config file, url value to SSH instead of HTTPS.

2.1 Go to the repo directory, open the file .git/config.

.git/config

[core]
      repositoryformatversion = 0
      filemode = true
      bare = false
      logallrefupdates = true
      ignorecase = true
      precomposeunicode = true
[remote "origin"]
      url = https://github.com/mkyong/spring-boot
      fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
      remote = origin
      merge = refs/heads/master

2.2 Update the url from HTTPS https://github.com/mkyong/spring-boot to SSH [email protected]:mkyong/spring-boot.git.

Terminal

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = [email protected]:mkyong/spring-boot.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

Done, try git push again.

References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
18 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Jim
1 year ago

my man. you made my day. clear and perfect description. thanks a lot.

Raghutnandan
2 years ago

Though I have updated URL in to .ssh/config file, Im still facing trouble for push.
ERROR: Repository not found.
fatal: Could not read from remote repository.

Emily
4 months ago

This was super helpful and clear, thank you! 🙂

mahmoud
11 months ago

Thanks man you are awesome

Greg Timmons
1 year ago

Thank you very much!

Sobral
1 year ago

Great job sir, I was on the verge of giving up on GitHub. This article was really helpful!

Chris
1 year ago

Great post! This is not the answer most are giving to this problem. It’s due (for me) to the deprecation of old repo w https url, even when I was using ssh. It failed with no proper error – but U’re idea fixed it.

Last edited 1 year ago by Chris
A;ex
1 year ago

Thank you so much!

Kris L
1 year ago

thank you so much!

Epope
1 year ago

really helpful! thanks!

powpow
1 year ago

This solved my problem. Thanks!

xiaoran
1 year ago

You saved me!!

thomas
1 year ago

You saved my nerves, thank you

emmanuel boutchouang
2 years ago

it keeps saying permission denied when i type .git/config

Alex
2 years ago

That was indeed the case, thanks!

Leonardo
2 years ago

Thank you, dude! It worked perfectly!

Simas
2 years ago

Thanks for the tip. It solved my problem 🙂

badre
2 years ago

thank you for your helping article.