How to Use Multiple GitHub Accounts on One Machine (Work + Personal) Using SSH

Struggling with Permission denied (publickey) when switching GitHub accounts? This guide shows you how to configure multiple GitHub accounts using SSH keys, host aliases, and automatic Git identity...

By · · 1 min read
How to Use Multiple GitHub Accounts on One Machine (Work + Personal) Using SSH

Source: DEV Community

Struggling with Permission denied (publickey) when switching GitHub accounts? This guide shows you how to configure multiple GitHub accounts using SSH keys, host aliases, and automatic Git identity switching. Set it up once. It works forever. ๐Ÿš€ Quick Setup (TL;DR) If you already understand SSH basics, hereโ€™s the entire flow: # 1. Create two SSH keys ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_work ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_personal # 2. Configure SSH aliases # ~/.ssh/config Host github-work HostName github.com User git IdentityFile ~/.ssh/id_ed25519_work Host github-personal HostName github.com User git IdentityFile ~/.ssh/id_ed25519_personal # 3. Clone using aliases git clone git@github-work:org/repo.git git clone git@github-personal:user/repo.git ๐Ÿ‘‰ If this makes sense, youโ€™re done ๐Ÿ‘‰ If not, continue for the full breakdown The Problem You have: One work GitHub account One personal GitHub account But SSH only sees: github