Keeping Work and Personal GitHub Accounts Separate 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.
Updated October 22, 2026

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.
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
Inspect the filenames before generating new keys. If a target file already exists, reuse it when appropriate or choose another filename; do not overwrite a key you still need.
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 "your-personal-email@example.com" -f ~/.ssh/id_ed25519_personal
Set a passphrase when prompted and use an SSH agent for convenience. Add only the public .pub key to GitHub; keep the private key on your machine.
Generate SSH Key for Work GitHub
Similarly, generate an SSH key for your work GitHub account:
ssh-keygen -t ed25519 -C "your-office-email@example.com" -f ~/.ssh/id_ed25519_office
Use a separate passphrase protected key for the work account.
Verify the Generated Keys
To confirm the keys have been created, run:
ls -la ~/.ssh
You should see the following files:
id_ed25519_personalandid_ed25519_personal.pubid_ed25519_officeandid_ed25519_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_ed25519_personal
IdentitiesOnly yes
# Office GitHub Account
Host github-office
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_office
IdentitiesOnly yes
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
- Copy the personal public key:
cat ~/.ssh/id_ed25519_personal.pub
- Go to GitHub Settings > SSH and GPG Keys > New SSH Key
- Paste the key and save
Work GitHub Account
- Copy the work public key:
cat ~/.ssh/id_ed25519_office.pub
- Go to your work GitHub account's Settings > SSH and GPG Keys > New SSH Key
- Paste the key and save
Step 5: Test SSH Connections
Test Personal Account
ssh -T github-personal
Confirm that the greeting names the intended account. GitHub does not provide shell access, so an authentication test can report successful authentication with a non zero exit status.
Expected greeting:
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 "your-personal-email@example.com"
Office Repository
git config user.name "Your Office GitHub Name"
git config user.email "your-office-email@example.com"
Verify Configuration
Check the settings in each repository:
git config --get user.name
git config --get user.email
Key Takeaways
- Use distinct SSH keys - Host aliases can select the intended authentication identity
- SSH Config File - The config file makes it easy to manage multiple accounts
- Repository Specific Configuration - Set user name and email per repository to avoid mix ups
- Test Your Setup - Always verify SSH connections before starting work
- Security First - Use passphrases for SSH keys to enhance security
After cloning, check git remote -v. For an existing clone, change the remote only if needed, for example, git remote set-url origin git@github-office:your-organization/your-repo.git.
Benefits of This Approach
Distinct authentication and author identity
The host aliases select different SSH keys. Repository configuration controls the author details written into commits. Check both, because an SSH alias alone does not prevent an incorrect commit email.
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.