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

18 comments on “GitHub keep asking for username password when git push

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

    Reply
  2. 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.

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

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

    Reply
  5. 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.

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *