How to execute a Git command using custom private key

By default, when running Git command on repositories accessed via SSH, Git uses your default private key, i.e. /.ssh/id_rsa. Suppose you have multiple SSH keys and you want Git to use a specific non-default one to perform a command, you may do this using a command like

GIT_SSH_COMMAND="ssh -i ~/.ssh/your_rsa_key" git push origin master

Note that you need Git 2.3 and newer.

References

How to tell git which private key to use? http://superuser.com/questions/232373/how-to-tell-git-which-private-key-to-use.

Leave a Reply

Your email address will not be published. Required fields are marked *