Git - Custom SSH Keys Per Repository
03/30/2022, WedAssign Git Profiles for Different Repositories
On occasions where you wish to associate different Git profiles to different repositories, such as when you have a work account and a personal account, one can achieve this by running a Git config command on repository level basis.
Assuming that you have already created two ssh keys within your .ssh
folder to separate your work vs personal Git repositories activities, and you want to pin a repository for work related activities, navigate into the Git repository of where you perform your work and run this command:
git config core.sshCommand "ssh -i ~/.ssh/your_select_ssh_key_name_for_work -F /dev/null"
Now suppose you have another Git folder which you only want to interact with your personal Git account, you will need to navigate to the personal repo and run this command:
git config core.sshCommand "ssh -i ~/.ssh/your_select_ssh_key_name_for_personal -F /dev/null"