Skip to content

Instantly share code, notes, and snippets.

@Lukas238
Created September 1, 2021 22:09
Show Gist options
  • Save Lukas238/2591e79421a691a4cdc8dba2e8492605 to your computer and use it in GitHub Desktop.
Save Lukas238/2591e79421a691a4cdc8dba2e8492605 to your computer and use it in GitHub Desktop.
Custom SSH key on Git command

Custom SSH key on Git command

The git (starting with git version 2.10) configuration core.sshCommand allow to pass arbitrary options to the SSH command, used on git pull, git fetch, and git push.

Using this configuration, we can pass a custom path to a ssh key, as well as a know_host file and or ssh .config file.

This is usefull in situations where you can run git commands from the shell, but do not have root access, like a exec() command executed from a PHP page.

[core]
	sshCommand = "ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=[ABSOLUTE PATH TO FILE]/know_hosts -i [ABSOLUTE PATH TO FILE]/id_rsa_custom_key -F /dev/null"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment