To work with different GitHub accounts on the command line by configuring multiple SSH keys and associating each key with a different GitHub account. Here’s how you can set it up:
ssh-keygen -t rsa -C "your_email@example.com"
id_rsa
and id_rsa_work
, and optionally set a passphrase.Start SSH Agent:
eval "$(ssh-agent -s)"
Add SSH Keys:
ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa_work
Create SSH Config File:
nano ~/.ssh/config
Configure SSH Hosts:
# Default GitHub account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# Work GitHub account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
id_rsa
and id_rsa_work
with the names of your SSH keys.id_rsa.pub
and id_rsa_work.pub
) to the corresponding GitHub account.git clone git@github.com:your_username/repo.git
git clone git@github.com-work:your_username/repo.git
your_username
and repo
with your GitHub username and repository name.Configure Global User:
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
Add, Commit, and Push Changes:
By following these steps, you can work with multiple GitHub accounts on the command line simultaneously.