Set Git SSH key separates by Git repository

20 May 2020

Usually we separate SSH key for Git base on host name like this:

User dev
IdentifyFile ~/.ssh/id_rsa

But, what if we want to use different keys for different repo and both repositories are hosted on Github.

We have to type input the private SSH key like this:

git push origin master -i ~/.ssh/another_ssh_key

Recently, I found another method to easy this process: Use Git config

git config core.sshCommand 'ssh -i ~/.ssh/another_ssh_key'

Then you can push code like normal:

git push origin master


Back to top