I am working on a couple of maven-projects where common java-classes is placed in a submodule. The submodule is then added to each maven-project and the project is cloned from a private github-repo to a docker container.
I have created a ssh-key for each project and the submodule, added the public key to 'Deploy keys' in 'Settings' in the github-repo. All keys are created without a password.
Downloading the main-repo went fine but adding the submodule failed with git@github.com: Permission denied (publickey).
. And hence the compile failed. Both keys were loaded before cloning the repo and updating the submodule.
It turns out I can have only one key loaded at a time. So I modified the script that clone so it unload all keys before loading the key for the submodule.
eval $(ssh-agent -s)
ssh-add /home/docker/.ssh/id_ed25519_maven_repo
ssh-keyscan -H github.com >> /home/docker/.ssh/known_hosts
cd /home/docker/code
git clone git@github.com:foo/main.git
cd main
ssh-add -D <--- Unload all keys ---
ssh-add /home/docker/.ssh/id_ed25519_submodule
git submodule init
git submodule update
mvn compile
Why must I unload and load before updating the submodule instead of having both keys loaded at the same time?
(spent hours troubleshooting)