Your Laptop → GitHub (Push / Pull via SSH)#
A. Generate SSH Keys (One per account)#
1️⃣ Personal GitHub account#
ssh-keygen -t ed25519 -C "personal@github" -f ~/.ssh/github_personal
Creates:
~/.ssh/github_personal
~/.ssh/github_personal.pub
2️⃣ Work GitHub account#
ssh-keygen -t ed25519 -C "work@company" -f ~/.ssh/github_work
Creates:
~/.ssh/github_work
~/.ssh/github_work.pub
B. Add PUBLIC keys to GitHub#
Personal account#
cat ~/.ssh/github_personal.pub
- GitHub → Personal Account → Settings → SSH Keys → Add
Work account#
cat ~/.ssh/github_work.pub
- GitHub → Work Account → Settings → SSH Keys → Add
C. SSH Config (CORE STEP)#
Create / edit config:
nano ~/.ssh/config
# Personal GitHub
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/github_personal
IdentitiesOnly yes
# Work GitHub
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/github_work
IdentitiesOnly yes
Permissions:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/config
D. Use Correct Remote URLs#
Personal repo#
git clone git@github.com-personal:USERNAME/repo.git
or update existing repo:
git remote set-url origin git@github.com-personal:USERNAME/repo.git
Work repo#
git clone git@github.com-work:ORG/repo.git
or:
git remote set-url origin git@github.com-work:ORG/repo.git
E. Test SSH Connections#
ssh -T git@github.com-personal
ssh -T git@github.com-work
Expected:
Hi USERNAME! You've successfully authenticated.
F. Git Identity (Recommended)#
Set per-repo identity:
Personal repo#
git config user.name "Your Name"
git config user.email "personal@email.com"
Work repo#
git config user.name "Your Work Name"
git config user.email "work@company.com"