Learn Note

Fixing GitHub Permission Denied Errors When Pushing a Repo

The Problem

I tried pushing my project and got this error:

GitHub Permission Denied Screenshot 1

What I Tried

  • Attempted push using HTTPS (even though I normally use SSH)
  • Creating a personal access token in GitHub
  • Clearing credentials in my Terminal

None of these worked.

What Actually Worked

Switching from HTTPS to SSH.

Steps:

  1. Verified the SSH key existed in Terminal
  2. Confirmed existing SSH key was already added to GitHub (no need to generate a new one)
  3. Changed remote to SSH
  4. Tested connection with ssh -T git@github.com
  5. Pushed successfully

After switching to SSH, the push finally worked:

GitHub Successful Push

Key Takeaways

  • GitHub no longer accepts passwords
  • SSH is more reliable than HTTPS
  • Credential caching can cause confusing errors

Notes

During my initial commit, I missed that the repo displayed the HTTPS URL instead of the usual SSH one. I copied the provided terminal commands rather than using my usual ones.

I haven’t created repos in a while, so I just followed the instructions as provided without thinking too much about it. When I first learned GitHub basics, the initial course taught me to use SSH first before HTTPS URL.

It took a few attempts to fix, but I’m glad the solution turned out to be relatively simple.