SSH clone from a Jenkins container

Well, I have a jenkins container running on a Debian VM. We would like to explore the SSH connectivity to the GitRepositories within our container.
Ideally, one would generate keys using ssh-keygen and copy the public key to the git repository.
This step should be sufficient to clone the git repository and I tried it myself on the Debian VM.

However, on the jenkins container, if I do a docker exec -it jenkinscontainerID /bin/bash and perform the same steps, it fails!
I cannot clone the repository. I get the following response :

Cloning into 'TestingRepo'...
git@git.XYZ.de: Permission denied (publickey).
fatal: Could not read from remote repository.

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

Is there any conceptual failure in my understanding that I am missing here?

I don’t see any conceptual failure in your understanding. It is likely a problem in your implementation. of the concept.

An ask.ubuntu.com article suggests ways that you can use the GIT_SSH_COMMAND environment variable to see more detailed information about the ssh operations being performed by git clone over ssh. You might compare the output from the working case with the output from the non-working case to see what is different. Some of the differences might include:

  • Wrong permissions on the .ssh directory
  • Wrong permissions on the private key file in the .ssh directory
  • Missing private key file in the .ssh directory
  • Different .ssh/config settings in the two locations cause a different private key to be used
  • Different network configurations in the two locations