Administrating servers or project, you might have to set up multiple git repositories on your linux server, each with its SSH key to use for the connection.

By default, Debian uses the id_rsa key (generated by default using ssh-keygen utility) for SSH connections. If it happen not to work for any connection, it wont try any other key and just fail.

Hopefully, Git uses SSH and it allows us to customize the SSH command issued by Git on a given repository. This is the core.sshCommand configuration.

There is two ways to set it :

  • Update the .git/config file, and at the end of the core section, add sshCommand = "ssh -i /path/to/private_key
  • Use the git utility inside the repository by using git config --local core.sshCommand "ssh -i /path/to/private_key"

By the end you will have the following inside .git/config

Last line is the most important one. Here my private key is located at ~/.ssh/belib_admin

This isn’t an original solution by me, I found it on CodeMaven.com.