Multiple Git accounts on your Mac/Window
Multiple Git ssh accounts – You are working under your business GitHub account. At the same time, you’d like to work on a personal/side project using your personal GitHub account.
Using multiple configurations inside your config file under your /.ssh folder. I’m using Github as an example.
Step by step
Generating ssh key pairs
Add public keys into your Github account
Update/Generate ssh config file (
#Default business Github account: khanh-business Host github.com HostName github.com User git AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa #Personal Github: khanh-personal Host github.com-personal HostName github.com User git AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa_personal
Add ssh private keys to your ssh agent
$ ssh-add ~/.ssh/id_rsa $ ssh-add ~/.ssh/id_rsa_personal
Test the connections of the ssh keys
$ ssh -T email@example.com $ ssh -T firstname.lastname@example.org
You may see this warning message regarding authenticity of host, go ahead with
The authenticity of host 'github.com (22.214.171.124)' can't be established. RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx: Are you sure you want to continue connecting (yes/no)?
If everything is OK, you will see these messages regarding successfully authenticated with Github
Hi khanh-business! You've successfully authenticated, but GitHub does not provide shell access. Hi khanh-personal! You've successfully authenticated, but GitHub does not provide shell access.
Now all done, clone your repositories using multiple GitHub ssh accounts
$ git clone email@example.com:username/your-repo.git /path/to/repo $ cd /path/to/repo $ git config user.email "firstname.lastname@example.org" $ git config user.name "your name"
To push to commits/changes to the remote URL
$ git remote set-url origin https://<your_username>:<git_access_token>@github.com/<your_username>/<repo>.git $ git push --set-upstream origin master
See how to get your personal access token https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token