Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell git which SSH config file to use

Tags:

git

ssh

ssh-keys

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.

like image 852
pfwd Avatar asked Dec 19 '16 09:12

pfwd


People also ask

How does Git decide which ssh key to use?

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”.

Which config file is git using?

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.

Which ssh key does Git use by default?

ssh/config it will use the default private key file. The default file is ~/. ssh/id_rsa or ~/. ssh/id_dsa or ~/.


1 Answers

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
like image 147
Jakuje Avatar answered Oct 17 '22 06:10

Jakuje