How to Work with Multiple GitHub Accounts Using SSH Keys
Prerequisites
- Git must be installed on your system. Download Git
- Git Bash (comes with Git for Windows) or a terminal application
- Access to both your personal and work GitHub accounts
How to Open Git Bash on Windows
After installing Git for Windows, you can open Git Bash by:
- Pressing the Windows key and typing "Git Bash"
- Clicking on the "Git Bash" app in the search results
Alternatively, you can right-click in any folder in File Explorer and select Git Bash Here to open a terminal in that directory.
If you use more than one GitHub account — for example, a personal and a work account — you've likely run into permission issues or confusing identity prompts. Here's a clean, reliable way to manage multiple GitHub accounts using SSH keys and a basic configuration.
Step 1: Create Two Separate SSH Keys
Open Git Bash and run these commands to generate your SSH keys:
# Generate personal SSH key
ssh-keygen -t ed25519 -C "your_personal_email@example.com" -f ~/.ssh/personal/id_ed25519_personal_nopass
# Generate work SSH key
ssh-keygen -t ed25519 -C "your_work_email@company.com" -f ~/.ssh/work/id_ed25519_work_nopass
What does
ed25519
mean?
ed25519
is a modern public-key signature algorithm that is faster and more secure than the olderrsa
algorithm. It is recommended for new SSH keys because of its strong security and performance.
Note: Press Enter when prompted for a passphrase (leave it blank for seamless usage).
Step 2: Add the Public Keys to GitHub
For each key:
- Run:
cat ~/.ssh/[your_key].pub
- Copy the output
- Go to GitHub → Settings → SSH and GPG Keys → New SSH key
- Paste the public key and save
Make sure you do this under the correct account (personal or work).
Step 3: Configure SSH to Use the Right Key
Open or create the SSH config file:
nano ~/.ssh/config
Add the following configuration:
# Personal GitHub
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/personal/id_ed25519_personal_nopass
IdentitiesOnly yes
# Work GitHub
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/work/id_ed25519_work_nopass
IdentitiesOnly yes
Step 4: Clone or Update Repositories
Use these hostnames instead of the default github.com
:
# Clone a personal repo
git clone git@github-personal:yourusername/your-personal-repo.git
# Clone a work repo
git clone git@github-work:yourworkaccount/your-work-repo.git
To update an existing repository:
git remote set-url origin git@github-personal:yourusername/your-personal-repo.git
Step 5: Test the Connection
Verify your setup by running:
ssh -T git@github-personal
ssh -T git@github-work
You should see a success message like:
Hi yourusername! You've successfully authenticated...
Final Thoughts
By separating your SSH keys and pointing each GitHub host to a specific one, you avoid all credential conflicts. This is a clean and secure way to manage multiple identities on the same machine, whether you're working across jobs, projects, or freelancing.