DEV Community

Cover image for 🔐How to Fix GitHub Authentication Failed: Switch from Password to Token or SSH
Chaitanya Rai
Chaitanya Rai

Posted on

2 1

🔐How to Fix GitHub Authentication Failed: Switch from Password to Token or SSH

If you've recently tried to push code to a private GitHub repository using HTTPS and encountered an error like this:

fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': abcd
remote: Support for password authentication was removed on August 13, 2021.
fatal: Authentication failed for 'https://github.com/test/cr/

Don't panic — you're not alone. This blog will explain why and how to fix it using GitHub's current authentication methods.

❓ Why This Happens
Since August 13, 2021, GitHub no longer supports password-based authentication for Git operations over HTTPS.

This change was made to improve security, and now developers must authenticate using either:

🔑 Personal Access Tokens (PAT)
🛡️ SSH Keys

✅ Solution 1: Use a Personal Access Token (HTTPS)

When Git prompts for a username and password, you should:

Enter your GitHub username as usual

Enter your Personal Access Token instead of your password

🔧 Steps to Create a Token:

  1. Go to GitHub → Settings → Developer Settings → Personal Access Tokens

  2. Click “Generate new token (classic)” or “Fine-grained token”

  3. Set expiration (e.g., 30 days)

  4. Select the **repo **scope

  5. Click Generate token

  6. Copy the token *immediately *(you won't see it again)

👨‍💻 Next, push your code:

git add .
git commit -m "Your commit message"
git push origin your-branch-name

When prompted:

Username:<Enter Your Github Username>

Password: Paste the token you generated

✅ Solution 2: Use SSH (Recommended for Long-Term)

If you regularly work with private repos, SSH is more convenient and secure.

🔧 Steps:

  1. Generate SSH Key:

ssh-keygen -t ed25519 -C "your-email@example.com"

  1. Add SSH Key to GitHub:

Copy the public key:

cat ~/.ssh/id_ed25519.pub

Then go to GitHub → Settings → SSH and GPG Keys
→ Click “New SSH Key”, paste the key, and save.

  1. Switch your remote URL:

git remote set-url origin git@github.com:OUP2/ernie.git

  1. Now push:

git push origin your-branch-name

🧠 Bonus: Cache Your Credentials (Optional)
To avoid typing your token repeatedly:

git config --global credential.helper cache
Or use GitHub’s credential manager for Windows/macOS.

🚀 You're Good to Go!
By replacing your GitHub password with a PAT or SSH key, you'll be compliant with GitHub’s current security policies and avoid annoying errors like HttpRequestException encountered.

Happy coding! 💻✨

ACI image

ACI.dev: Best Open-Source Composio Alternative (AI Agent Tooling)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Star our GitHub!

Top comments (0)

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

Delve into a trove of insights in this thoughtful post, celebrated by the welcoming DEV Community. Programmers of every stripe are invited to share their viewpoints and enrich our collective expertise.

A simple “thank you” can brighten someone’s day—drop yours in the comments below!

On DEV, exchanging knowledge lightens our path and forges deeper connections. Found this valuable? A quick note of gratitude to the author can make all the difference.

Get Started