cd ~/.ssh
ssh-keygen -t rsa -C "my@personal" -f "github-personal"
ssh-keygen -t rsa -C "my@work" -f "github-work"
ssh-add --apple-use-keychain ~/.ssh/github-personal
ssh-add --apple-use-keychain ~/.ssh/github-work
Copy public keys to clipboard:
pbcopy < ~/.ssh/github-personal.pub # Add to personal GitHub account
pbcopy < ~/.ssh/github-work.pub # Add to work GitHub account
Create or edit ~/.ssh/config
:
open -e ~/.ssh/config
Add these host configurations:
# Personal GitHub Account
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/github-personal
# Work GitHub Account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/github-work
Set default account globally:
git config --global user.name "your_personal_username"
git config --global user.email "[email protected]"
Clone new repositories:
git clone [email protected]:owner/repo.git # For personal
git clone [email protected]:owner/repo.git # For work
Update existing repositories:
git remote rm origin
git remote add origin [email protected]:owner/repo.git
git remote set-url origin [email protected]:owner/repo.git
Set repository-specific user:
Default git info set to personal, so for work projects manually change git user.name and user.email
git config user.email "[email protected]"
git config user.name "Your Name"
ssh-add -l # Check if keys are loaded
If keys missing, add them again:
ssh-add --apple-use-keychain ~/.ssh/github-personal
ssh-add --apple-use-keychain ~/.ssh/github-work