If you're just starting out in DevOps, you've probably hit that wall: you've generated your SSH keys, you've added the public one to GitHub, and yet...
git push origin main
# Error: Permission denied (publickey)
It's maddening, isn't it? You've done all the steps, but GitHub still won't let you in. I spent ages on this, so let me save you the headache.
The Key Pair is Only Half the Story
We all know the basics of SSH authentication:
•
The Public Key (.pub): This is the one you give to GitHub. It's like the lock on the door.
•
The Private Key: This stays on your machine. It's the actual key that opens the lock. Keep it safe!
I had both, and I had the right lock on the door. So what was the problem?
The Missing Link: The SSH Agent
Here's the bit that often gets left out of the beginner tutorials: your computer needs a way to use that private key automatically. That's where the SSH Agent comes in.
Think of the Agent as a secure, temporary vault for your private keys. When you try to push code, the Agent automatically presents the key to GitHub. If the Agent isn't running, or if you haven't loaded your key into it, your terminal has no idea how to prove your identity.
This was my "Aha!" moment. I hadn't told my system to load the key!
The Two-Line Fix That Changes Everything
If you've generated your key and added the public part to GitHub, this is likely the missing piece of the puzzle. Run these two commands in your terminal:
# 1. Start the SSH agent (if it's not already running)
eval "$(ssh-agent -s)"
# 2. Load your private key into the agent
ssh-add ~/.ssh/id_ed25519
Pro Tip: If you used a different name for your key, adjust the path in the ssh-add command.
Once you've done that, you can test the connection:
ssh -T git@github.com
# You should see: Hi [YourUsername]! You've successfully authenticated... 🎉
And just like that, your git push will work without a password.
Why This Matters for DevOps
This isn't just a convenience; it's a fundamental part of the DevOps workflow. Automated systems—like CI/CD pipelines or deployment scripts on a server—can't type passwords. SSH keys, managed by the Agent, provide the secure, non-interactive authentication that makes automation possible.
If you're hitting this error, you're not alone. It's a classic beginner hurdle. Now you know the secret sauce!
Top comments (0)