DEV Community

Cover image for πŸ” Managing Multiple GitHub Accounts with SSH: Personal & Work Setup Guide
Popoola Temilorun
Popoola Temilorun

Posted on

πŸ” Managing Multiple GitHub Accounts with SSH: Personal & Work Setup Guide

If you've ever struggled to juggle your personal and work GitHub accounts on the same machine, this guide is for you.

In this step-by-step tutorial, you'll learn how to:

βœ… Generate SSH keys for different GitHub accounts
βœ… Configure SSH with aliases for each identity
βœ… Clone repositories using SSH without constant authentication issues

Let’s dive in πŸ‘‡


1. Generate SSH Keys for Personal and Work GitHub Accounts

Start by creating two separate SSH keysβ€”one for each GitHub account.

# Personal GitHub account
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519 

# Work GitHub account
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_work
Enter fullscreen mode Exit fullscreen mode

πŸ“ Notes:

  • The -f flag specifies the filename.
  • Use meaningful filenames like id_ed25519 and id_rsa_work for clarity.

2. Add Your Public Keys to GitHub

Copy the contents of each public key and add them to their respective GitHub accounts:

# Display the public key
cat ~/.ssh/id_ed25519.pub      # Personal
cat ~/.ssh/id_rsa_work.pub     # Work
Enter fullscreen mode Exit fullscreen mode

Then:

  1. Go to your GitHub Settings > SSH and GPG keys
  2. Click "New SSH Key"
  3. Paste the key content and save

Image description
Repeat this process for both personal and work accounts.


3. Configure the SSH Config File for Multiple Identities

Create or update your ~/.ssh/config file to define aliases for each account:

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

# Work GitHub
Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_work
Enter fullscreen mode Exit fullscreen mode

πŸ› οΈ You can edit this file using your favorite text editor:

code ~/.ssh/config    # VS Code
nano ~/.ssh/config    # Terminal editor
Enter fullscreen mode Exit fullscreen mode

Image description

4. Test Your SSH Connections

Verify your setup with:

ssh -T git@github-personal
ssh -T git@github-work
Enter fullscreen mode Exit fullscreen mode

βœ… You should see:

Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.
Enter fullscreen mode Exit fullscreen mode

Image description

5. Clone Repositories Using SSH Aliases

Now you can clone repos with the correct identity by using the aliases:

# Personal repo
git clone git@github-personal:your_personal_username/repo.git

# Work repo
git clone git@github-work:your_work_org/repo.git
Enter fullscreen mode Exit fullscreen mode

No more switching keys or editing global settings!


6. Set Local Git User Info for Work Repositories

To ensure your work commits use the correct email and name:

cd path/to/work-repo

git config user.name "Your Work Name"
git config user.email "[email protected]"
Enter fullscreen mode Exit fullscreen mode

This updates the local .git/config file and overrides the global config.

πŸ” Check your Git identity:

git config user.name
git config user.email
Enter fullscreen mode Exit fullscreen mode

πŸŽ‰ You're All Set!

With this setup, you can seamlessly manage multiple GitHub accounts on one machine using SSH. It's a clean and secure way to avoid authentication conflicts and commit with the correct identity every time.


πŸ“Œ TL;DR

  • Use different SSH keys for personal and work accounts
  • Define aliases in ~/.ssh/config
  • Clone repos using the correct alias
  • Set local Git user info per project

πŸ’¬ Got questions or a better SSH setup? Connect on LinkedIn

Top comments (0)