お問い合わせ
image

Managing Multiple GitHub Accounts: How to Fix “Permission Denied” Errors

制作・開発
profile

Iftekhar Eather

Have you ever tried to push code to your personal GitHub repository, only to be met with 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.

The Problem

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-personal in 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!

関連投稿

blog-thumb

AI FOMOを乗り越える

AI FOMOを乗り越える —— 新技術の追求から課題解決への転換 ...

blog-thumb

コンテキストの限界を突破する

コンテキストの限界を突破する —— 「読む」AIから、「文脈を創る」AIへの進化 ...

blog-thumb

S3 Website Hosting 向けに Lambda 関数で Basic Auth を実装する

本記事は、英語で公開されている弊社ブログ記事の日本語翻訳版です。
英語元記事:Implement Basic AUth using lambda function for S3 Website Hosting