5

I've set the core.sshCommand option for a repo so that I could use a different ssh key when working with it (i.e. sshCommand = ssh -i /path/to/key). However, when I run git submodule update this option is not considered:

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Is there any way I can configure the repo to use the given ssh key for itself and any submodules?

planetp
  • 14,248
  • 20
  • 86
  • 160

2 Answers2

7

Either set it globally:

git config --global core.sshCommand "ssh -i /path/to/key"

But that sets the key for every repository you work with.

Or set it for every submodule:

git submodule foreach git config core.sshCommand "ssh -i /path/to/key"
phd
  • 82,685
  • 13
  • 120
  • 165
  • Not working for me. Unable to add a submodule as it is picking the wrong ssh key – Arka Prava Basu Dec 27 '19 at 12:51
  • `git submodule foreach` runs through the existing submodules. For a new submodule just being added you need something like `git -c core.sshCommand="ssh -i /path/to/key" submodule add` – phd Dec 27 '19 at 13:51
3

According to this answer, from where I pulled this quote,

The core.sshCommand option was added to git 2.10.0. You're running 2.7.4, which doesn't have that functionality. You'd need to upgrade to a newer Git if you wanted to use it.

If you are running a very old version, be mindful of the changes. You can consult this changelog.

You can use the environmental variable GIT_SSH_COMMAND instead.

export GIT_SSH_COMMAND="/usr/bin/ssh -i /your/path/to/id_rsa"
John Strood
  • 1,859
  • 3
  • 26
  • 39