the wiki of cscosine
This guide resets all SSH keys and rebuilds a clean multi-account Git setup (e.g., personal + work).
It also includes how to verify and fix repository remotes to ensure the correct SSH identity is used.
First inspect your current SSH directory:
ls -al ~/.ssh
If you want a complete reset:
rm -rf ~/.ssh
mkdir ~/.ssh
chmod 700 ~/.ssh
This removes:
Remove any keys currently loaded in the SSH agent:
ssh-add -D
Verify itβs empty:
ssh-add -l
Expected result:
The agent has no identities.
Using ed25519 is recommended.
ssh-keygen -t ed25519 -C "personal@email.com"
Save as:
~/.ssh/id_ed25519_personal
ssh-keygen -t ed25519 -C "work@email.com"
Save as:
~/.ssh/id_ed25519_work
Resulting files:
~/.ssh/id_ed25519_personal
~/.ssh/id_ed25519_personal.pub
~/.ssh/id_ed25519_work
~/.ssh/id_ed25519_work.pub
Edit the SSH config file:
nano ~/.ssh/config
Example configuration:
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
IdentitiesOnly yes
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
Set proper permissions:
chmod 600 ~/.ssh/config
This creates SSH aliases:
github-personalgithub-workThese force Git to use the correct key.
ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_work
Verify:
ssh-add -l
You should see both keys listed.
Print the public key:
cat ~/.ssh/id_ed25519_personal.pub
Add it to:
GitHub β Settings β SSH and GPG keys
Repeat for the work key:
cat ~/.ssh/id_ed25519_work.pub
Add it to the work account.
Test each SSH identity.
ssh -T git@github-personal
ssh -T git@github-work
Expected message:
Hi username! You've successfully authenticated.
Use the SSH aliases defined earlier.
git clone git@github-personal:username/repo.git
git clone git@github-work:company/repo.git
This ensures Git uses the correct SSH key automatically.
Inside any repository, check the configured remote:
git remote -v
Example output:
origin git@github.com:username/repo.git (fetch)
origin git@github.com:username/repo.git (push)
If you see git@github.com, then your SSH config alias is NOT being used.
Correct multi-account setup should look like:
origin git@github-personal:username/repo.git
or
origin git@github-work:company/repo.git
To update the remote URL:
git remote set-url origin git@github-personal:username/repo.git
git remote set-url origin git@github-work:company/repo.git
Verify the fix:
git remote -v
If authentication problems occur, run:
ssh -vT git@github-personal
or
ssh -vT git@github-work
Look for the line:
Offering public key: ~/.ssh/id_ed25519_personal
This confirms the correct key is being used.
Global default:
git config --global user.name "Your Name"
git config --global user.email "personal@email.com"
For work repositories:
git config user.email "work@email.com"
Verify:
git config --list
You now have: