2 minutes
Fixing ‘ERROR: Permission denied’ on Github Permission
Do you have multiple GitHub accounts? Have you ever faced a problem with GitHub permissions when revisiting an old project stored in your old GitHub account? When you try to push changes or pull code from your terminal on your local machine, you get an error like this:
ERROR: Permission to old_account_username/old_repository.git denied to new_account_username
If you’ve ever run into this problem, don’t worry—you’re not alone. I ran into the same thing. After making some changes to a project on my new GitHub account, I couldn’t push or pull from my old project on my old GitHub account anymore.
This error occurs because you are trying to push to a repository under your old GitHub account (old_account) using the credentials (SSH key) of your new GitHub account (new_account).
okay, so in this post, i want to share how to fix it. Let’s get started! 🚀
1. Check Your SSH Configuration
Open your ssh configuration file in ~/.ssh/config and ensure you have a configuration for all your github account.
if the file doesn’t exist, create it, and write like this configuration example :
# Old GitHub Account
Host github.com-old # this host alias for your old github account
HostName github.com
User git
IdentityFile ~/.ssh/id_oldaccount_ed25519
# New GitHub Account
Host github.com-new # this host alias for your old github account
HostName github.com
User git
IdentityFile ~/.ssh/id_newaccount_rsa
Note :
In my case i use id_ed25519 for ssh access to my old github account
and use id_rsa for my new account.
2. Update Your Git Remote URL
first check your current remote URL on your old project :
git remote -v
and then, you will see something like this :
origin [email protected]:your-old-account/your-repo.git
Next, you need to update it to explicitly use the github.com-old or whatever you put as the host alias in (~/.ssh/config).
git remote set-url origin [email protected]:your-old-account/your-repo.git
3. Verify SSH Connection for Old Account
Ensure that the SSH connection works for your old account:
ssh -T [email protected]
You should see output like this :
Hi Your-Old-Account! You've successfully authenticated...
4. Push Or Pull Your Changes
Now you should be able to push or pull your old repository on your old account.
git push origin main