#Development Tools

Multiple GitHub Accounts on Windows: The Ultimate SSH Configuration Guide"

October 20, 20246 min read

Multiple GitHub Accounts on Windows: The Ultimate SSH Configuration Guide

In today's development landscape, managing multiple GitHub accounts has become a common necessity. Whether you're balancing personal projects with work responsibilities or managing different client accounts, this guide will show you how to seamlessly handle multiple GitHub accounts on Windows using SSH with the hostname approach.

The Challenge

Many developers face the need to manage multiple GitHub accounts:

  • Personal projects repository
  • Work-related repository
  • Client-specific repositories
  • Open-source contribution accounts

The traditional approach of switching between HTTPS credentials can be cumbersome. Enter SSH with hostname configuration - your elegant solution to this modern development challenge.

Prerequisites: Your Development Arsenal

Before we begin, ensure you have:

  • Git installed on your Windows machine
  • Access to all your GitHub accounts
  • Windows Terminal or Git Bash
  • Basic understanding of SSH concepts

Step 1: Generating SSH Keys - Your Digital Signatures

First, let's create unique SSH keys for each GitHub account. Open your terminal and run:

# For your personal account
ssh-keygen -t ed25519 -C "personal@email.com" -f ~/.ssh/id_ed25519_personal

# For your work account
ssh-keygen -t ed25519 -C "work@company.com" -f ~/.ssh/id_ed25519_work

When prompted for a passphrase, it's recommended to set one for additional security.

Step 2: SSH Config Magic - The Hostname Architecture

Create or edit your SSH config file at ~/.ssh/config:

# Create if it doesn't exist
touch ~/.ssh/config

Add the following configuration:

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

# Work GitHub Account
Host github.com-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_work
    IdentitiesOnly yes

Step 3: Adding SSH Keys to GitHub - Key Registration

Now, let's add these SSH keys to your GitHub accounts:

For Personal Account:

# Copy your personal SSH public key
clip < ~/.ssh/id_ed25519_personal.pub
  1. Go to GitHub.com and log in to your personal account
  2. Navigate to Settings → SSH and GPG keys → New SSH key
  3. Give it a descriptive title (e.g., "Windows Personal Machine")
  4. Paste your key and save

For Work Account:

# Copy your work SSH public key
clip < ~/.ssh/id_ed25519_work.pub

Repeat the same process for your work account.

Step 4: Testing Your Configuration - The Verification Phase

Verify your SSH connections:

# Test personal account connection
ssh -T github.com-personal

# Test work account connection
ssh -T github.com-work

You should see success messages like:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

Step 5: Repository Configuration - The Final Piece

For New Repositories:

When cloning new repositories, use the appropriate hostname:

# Personal projects
git clone git@github.com-personal:username/repository.git

# Work projects
git clone git@github.com-work:company/repository.git

For Existing Repositories:

Update the remote URL for existing repositories:

# Check current remote
git remote -v

# Update remote URL for personal projects
git remote set-url origin git@github.com-personal:username/repository.git

# Update remote URL for work projects
git remote set-url origin git@github.com-work:company/repository.git

Step 6: Git Configuration - Account-Specific Settings

Set up different Git configurations for different projects:

Global Configuration (Personal):

git config --global user.name "Your Personal Name"
git config --global user.email "personal@email.com"

Repository-Specific Configuration (Work):

cd /path/to/work/repository
git config user.name "Your Work Name"
git config user.email "work@company.com"

Pro Tips: Advanced Configuration

1. Create Project-Specific Scripts

Save this as setup-work-repo.bat:

@echo off
git config user.name "Your Work Name"
git config user.email "work@company.com"
echo Work git configuration applied!

2. SSH Agent Configuration

Add this to your PowerShell profile:

# Start SSH agent automatically
$env:GIT_SSH = "C:\Windows\System32\OpenSSH\ssh.exe"

function Start-SshAgent {
    if (! (ps | ? { $_.Name -eq "ssh-agent"})) {
        Start-Service ssh-agent
    }
}

Start-SshAgent

3. Directory-Based Configuration

Create a .gitconfig in your work projects directory:

[user]
    name = Your Work Name
    email = work@company.com
[core]
    sshCommand = "ssh -i ~/.ssh/id_ed25519_work"

Troubleshooting: Common Challenges

1. Authentication Failed

If you see "Authentication failed", check:

  • SSH key is properly added to GitHub
  • Correct hostname is used in git remote URL
  • SSH agent is running (ssh-agent -s)

2. Wrong Account Used

If the wrong account is used:

  • Verify remote URL (git remote -v)
  • Check local git configuration (git config --list)
  • Ensure SSH config hostname matches remote URL

3. Permission Denied

For "Permission denied" errors:

# Check SSH key permissions
icacls %USERPROFILE%\.ssh\id_ed25519_personal
icacls %USERPROFILE%\.ssh\id_ed25519_work

Conclusion: Your Multi-Account Setup Complete

Managing multiple GitHub accounts on Windows doesn't have to be complicated. With this SSH hostname approach, you can:

  • Seamlessly switch between accounts
  • Maintain separate configurations
  • Avoid credential conflicts
  • Enhance your development workflow

Remember to:

  • Keep your SSH keys secure
  • Regularly update your SSH key passphrases
  • Maintain clear naming conventions
  • Document your configuration

The future of development often involves managing multiple identities and accounts. With this setup, you're well-prepared to handle any number of GitHub accounts efficiently and securely.

Video Tutorial

For a visual walkthrough of this process, check out this helpful tutorial:

Kiran Kumar headshot

Kiran Kumar is a full-stack developer with 2 years of experience and over 20 freelance projects deployed, specializing in creating seamless applications and enhancing user experiences across the web.