Why Git Push Fails Even When SSH Is Set Up
A common GitHub issue many developers face is this:
-
ssh -T git@github.com✅ works -
git push❌ fails withPermission denied (publickey)
At first glance, this feels confusing. If SSH authentication works, why can’t Git push?
The answer lies in the SSH agent.
The Real Problem: SSH Agent Has No Keys Loaded
When you run:
ssh-add -l
and see no output, it means:
The SSH agent is running, but no SSH keys are loaded into it.
So even though:
-
Your SSH key exists on disk
-
Your SSH key is added to GitHub
-
Authentication can work in some cases
👉 git push has no key to use, and GitHub rejects the request.
Why ssh -T git@github.com Can Still Work
This is the confusing part.
-
ssh -Tmay try keys directly from disk -
Your OS keychain may temporarily supply a key
-
But Git relies strictly on the SSH agent
So authentication appears fine, but authorization during push fails.
The Immediate Fix
Run these two commands:
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_ed25519
Verify:
ssh-add -l
You should now see your key listed.
After this:
git push
✅ Works.
Do You Have to Do This Every Time?
By default: yes, once per terminal session.
Each new terminal starts with an empty SSH agent.
Make It Permanent (Recommended)
Add this to ~/.bashrc or ~/.zshrc:
eval "$(ssh-agent -s)" > /dev/null ssh-add ~/.ssh/id_ed25519 2>/dev/null
Now:
-
Open a terminal
-
SSH key is automatically loaded
-
Git push works every time
Key Takeaway
SSH setup is not enough — the SSH agent must have your key loaded.
Most “mysterious” GitHub permission errors come down to this single missing step.
Once fixed, your Git workflow becomes seamless and predictable.