Back to Blog
GitHubUbuntuSSHDeveloperProductivity

How to Manage Two GitHub Accounts on Ubuntu

Managing two GitHub accounts (e.g., personal and work) on the same machine can be tricky, but it's possible with proper SSH key configuration. Follow this step-by-step guide to set up and use multiple GitHub accounts on Ubuntu.

D
Dheeraj Jha
January 28, 2025
4 min read
How to Manage Two GitHub Accounts on Ubuntu

Introduction

Managing two GitHub accounts (e.g., personal and work) on the same machine can be tricky, but it's possible with proper SSH key configuration. Follow this step-by-step guide to set up and use multiple GitHub accounts on Ubuntu.

GitHub SSH Configuration Photo by Roman Synkevych on Unsplash

Step 1: Check Existing SSH Keys

Before generating new SSH keys, check if there are any existing keys on your system. Open a terminal and run:

ls -al ~/.ssh

This will list all the SSH keys currently available in your system.

Step 2: Generate SSH Keys for Personal and Work Accounts

Generate SSH Key for Personal GitHub

Run the following command to create an SSH key for your personal GitHub account:

ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_rsa_personal

When prompted for a passphrase, you can leave it empty or set one (recommended for security).

Generate SSH Key for Work GitHub

Similarly, generate an SSH key for your work GitHub account:

ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_rsa_office

Again, set a passphrase or leave it empty.

Verify the Generated Keys

To confirm the keys have been created, run:

ls -la ~/.ssh

You should see the following files:

  • id_rsa_personal and id_rsa_personal.pub
  • id_rsa_office and id_rsa_office.pub

Step 3: Configure SSH for Multiple GitHub Accounts

Create or Edit the SSH Config File

Open or create the SSH config file:

nano ~/.ssh/config

Add Configurations for Both Accounts

Paste the following configuration into the file:

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

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

Save and Exit

Press Ctrl+O, then Enter, and Ctrl+X to save and exit.

Set Correct Permissions

Ensure the correct permissions for the config file:

chmod 600 ~/.ssh/config

Step 4: Add SSH Keys to GitHub Accounts

Personal GitHub Account

  1. Copy the personal public key:
cat ~/.ssh/id_rsa_personal.pub
  1. Go to GitHub Settings > SSH and GPG Keys > New SSH Key
  2. Paste the key and save

Work GitHub Account

  1. Copy the work public key:
cat ~/.ssh/id_rsa_office.pub
  1. Go to your work GitHub account's Settings > SSH and GPG Keys > New SSH Key
  2. Paste the key and save

Step 5: Test SSH Connections

Test Personal Account

ssh -T github-personal

Expected output:

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

Test Office Account

ssh -T github-office

Expected output:

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

Step 6: Clone Repositories with Correct SSH Config

Clone Personal Repos

git clone git@github-personal:your-username/your-repo.git

Clone Office Repos

git clone git@github-office:your-organization/your-repo.git

Step 7: Configure Git User for Each Repository

Personal Repository

git config user.name "Your Personal GitHub Name"
git config user.email "[email protected]"

Office Repository

git config user.name "Your Office GitHub Name"
git config user.email "[email protected]"

Verify Configuration

Check the settings in each repository:

git config --get user.name
git config --get user.email

Key Takeaways

  1. Use SSH Keys - Different SSH keys for different GitHub accounts ensure clean separation
  2. SSH Config File - The config file makes it easy to manage multiple accounts
  3. Repository-Specific Configuration - Set user name and email per repository to avoid mix-ups
  4. Test Your Setup - Always verify SSH connections before starting work
  5. Security First - Use passphrases for SSH keys to enhance security

Benefits of This Approach

Complete Isolation

Keep your personal and work GitHub activities completely separate, preventing accidental commits to the wrong account.

Easy Switching

No need to constantly log in and out. Just use the appropriate host alias when cloning or adding remotes.

Professional Organization

Maintain different identities for different contexts, making your commit history clean and professional.

Conclusion

Managing multiple GitHub accounts on Ubuntu becomes straightforward once you set up SSH keys properly. This configuration ensures that your personal and work projects remain separate, preventing any mix-ups in commits or repository access. Take the time to set this up correctly once, and you'll save yourself from headaches down the road.


Need help with your Git workflow or development setup?
Portfolio: dheerajjha.com