I have multiple ssh config folders for various systems e.g.:
ssh -F ~/.ssh/system-a/config user@system-a
ssh -F ~/.ssh/system-b/config user@system-b
Each folder has a config file and set of identity files like so
Host system-a
HostName <some_hostname>
User <some_username>
IdentityFile ~/.ssh/system-a/keys/system-a.pem
How do tell git to use a certain ssh config file or a certain ssh key when performing git tasks?
Ideally I would like to do this per git project if I can.
Git does not know, or care. It just runs ssh. Specifies that ssh(1) should only use the authentication identity files configured in the ssh_config files, even if ssh-agent(1) or a PKCS11Provider offers more identities. The argument to this keyword must be “yes” or “no”.
The system level configuration file lives in a gitconfig file off the system root path. $(prefix)/etc/gitconfig on unix systems. On windows this file can be found at C:\Documents and Settings\All Users\Application Data\Git\config on Windows XP, and in C:\ProgramData\Git\config on Windows Vista and newer.
ssh/config it will use the default private key file. The default file is ~/. ssh/id_rsa or ~/. ssh/id_dsa or ~/.
on command-line you can change your Git config for the current repository:
git config core.sshCommand "ssh -F ~/.ssh/system-a/config"
or in .git/config
in your local repository to the [core]
section:
sshCommand = "ssh -F ~/.ssh/system-a/config"
This works only with git 2.10 and newer. Otherwise, it needs to be set up using environment variable $GIT_SSH_COMMAND
, for example like:
GIT_SSH_COMMAND="ssh -F ~/.ssh/system-a/config" git pull
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With