Back to Blog
githublinux

Managing Multiple GitHub Accounts

How to Fix “Permission Denied” Errors

Iftekhar Ahmed Eather2 min read

Have you ever tried pushing code to your personal GitHub repository only to encounter a frustrating error like this?

ERROR: Permission to personal-user/repo.git denied to office-user.

It's a classic headache. Your computer is “helpfully” trying to use your professional work credentials for your personal projects. Today, I'm going to show you the cleanest way to fix this using the SSH Config method.

By default, Git and SSH often grab the first key they find (usually your work key) and offer it to GitHub. GitHub recognizes you as your “Work Self,” realizes that “Work Self” doesn't have permission to write to “Personal Repo,” and shuts the door.

The Solution: The ~/.ssh/config File

The most elegant way to solve this is to create “aliases” for GitHub. This tells your computer exactly which key to use for which account.

Step 1: Create your SSH Keys

Ensure you have separate keys for both accounts.

id_rsa_office
id_rsa_personal

Step 2: Edit your SSH Config

Open your terminal and type:

nano ~/.ssh/config

Step 3: Add the Configuration Block

Paste the following (adjusting the filenames to match yours):

# Office GitHub Account
Host github.com-office
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_office

# Personal GitHub Account
Host github.com-personal
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_personal

Step 4: Update your Remote URL

Now, when you clone a repo or add a remote for your personal project, you use the alias ( github.com-personal) instead of just github.com.

If you already have a project folder, update the remote like this:

git remote set-url origin git@github.com-personal:your-username/your-repo.git

Step 5: Don't forget the Local Config!

To make sure your commits have the right name and email, run these inside your project folder:

git config user.name "Your Name"
git config user.email "your-personal-email@gmail.com"

Why this works

By using github.com-personalIn your remote URL, you trigger the specific block in your config file. Your computer now knows: "Ah! For this specific URL, I must use the personal key and ignore the office one."

Conclusion

No more switching keys manually or getting permission errors. With a small edit to your ~/.ssh/config You can seamlessly jump between professional work and open-source side projects!