1

I am using a collaborative user, so it is not possible to change global folder. I have a git repository connected with several remotes. I need to access different remotes with different rsa key. Is it possible to insert the key path within native git, e.g. maybe inside .git/config, so I don't need to repeat entering the key path when i am doing clones,fetches,pushes,pulls?

Edit: I am aware of similar questions, for example Specific RSA keys per git repo, but it does not provide an exact answer to "per repo".

Community
  • 1
  • 1
orb
  • 175
  • 2
  • 13
  • In what way does http://stackoverflow.com/questions/14106982/specific-rsa-keys-per-git-repo not answer this question? Where does the `.ssh/config` solution fail you? – Guildencrantz Jan 11 '16 at 03:34
  • @Guildencrantz I cannot change .ssh/config as the user on that machine is a collaborative user, changing it will force all other login sessions to use the same setting, so I need a solution for repository-wise rather than a single config file and let git autoload it – orb Jan 11 '16 at 13:53

1 Answers1

1

You need to replace the ssh url of your submodules by ssh url using ~/.ssh/config entry names (with ~ refering the $HOME of the global user)

Your ~/.ssh/config will include the path of the relevant private keys:

Host repo1
  HostName git.myhost.lan
  User git
  IdentityFile /path/to/global/user/.ssh/repo1PrivateKey

And for the submodule repo1:

git config --file=.gitmodules submodule.repo1 .url repo1:user/repo1
# if needed to follow a branch (if not, skip it)
git config --file=.gitmodules submodule.repo1 .branch abranch
git submodule sync
git submodule update --init --recursive --remote
git add .
git commit -m "Change submodule repo1 url"
git push

Note: git config + git submodule sync can be replaced.
See "Git submodule url changed" and the new command (Git 2.25, Q1 2020)

git submodule set-url [--] <path> <newurl>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Is it possible to save the ~/.ssh/config in for example $repo/.git/sshconfig and do something on $repo/.git/config (or similar) to force it use $repo/.git/sshconfig for a specific remote / all remote/ etc. ? – orb Jan 11 '16 at 13:55
  • @orb technically, config can be anywhere, provided none of its parent folders has a 'w' (write) in its chmod rights (or ssh deems the all access too "unsecure" to proceed). I am not aware of a config for ssh. Maybe `core.gitProxy` but I haven't tested it. – VonC Jan 11 '16 at 14:11