Fixing Heroku SSH Permission Denied Errors
Just spent way too much time debugging a frustrating Heroku deployment issue. Keep getting "Permission denied (publickey)" errors when trying to push to Heroku.
The Error
Every time I tried to push to Heroku, I got:
Permission denied (publickey).
fatal: Could not read from remote repository.
This was confusing because I could push to GitHub just fine with the same SSH key.
The Solution
Turns out Heroku needs to know about your SSH key explicitly. Even if you have a key set up for GitHub, Heroku maintains its own list of authorized keys.
Step 1: Generate SSH Key (if you don't have one)
ssh-keygen -t rsa
Just press Enter to accept the default location and optionally add a passphrase.
Step 2: Add Key to Heroku
heroku keys:add
This command will automatically find your public key and add it to your Heroku account.
Verifying the Fix
You can check which keys Heroku knows about:
heroku keys
And test the connection:
ssh -v git@heroku.com
Heroku uses its own git hosting infrastructure, separate from GitHub. Even though you might be using the same SSH key, each service needs to be told about it explicitly.
It's one of those things that makes perfect sense once you understand it, but can be confusing when you're starting out with Heroku.