Search code examples
gitsshbuildbot

git ls-remote fails when logged out


I'm facing a strange problem with the "git ls-remote command". I get the following error message when I am logged out :

Permission denied (publickey). fatal: Could not read from remote repository.

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

It appears when I try to use buildbot and I don't know how to solve it.

I managed to simulate the problem with a simple script loop.sh :

for i in {1..100}
do
   echo "$i ls-remote"
   git ls-remote git+ssh://git@sourcesup.renater.fr:2222/simol.git
   echo
   sleep 4
done

I run this script using screen. It works when I am logged in:

1 ls-remote 3d461dd036960bb69a90a4259789bed5dc2741f7 HEAD 3d461dd036960bb69a90a4259789bed5dc2741f7 refs/heads/master

2 ls-remote 3d461dd036960bb69a90a4259789bed5dc2741f7 HEAD 3d461dd036960bb69a90a4259789bed5dc2741f7 refs/heads/master

3 ls-remote 3d461dd036960bb69a90a4259789bed5dc2741f7 HEAD 3d461dd036960bb69a90a4259789bed5dc2741f7 refs/heads/master

Then, I log out... wait for some seconds, and log in again. The git ls-remote command fails. In this example, I logged out after the 13th iteration:

13 ls-remote 3d461dd036960bb69a90a4259789bed5dc2741f7 HEAD 3d461dd036960bb69a90a4259789bed5dc2741f7 refs/heads/master

14 ls-remote Permission denied (publickey). fatal: Could not read from remote repository.

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

15 ls-remote Permission denied (publickey). fatal: Could not read from remote repository.

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

Do you know how to solve this problem?

Thank you very much!


Solution

  • Thank you very much for your help.

    I finally found a solution to my problem. I have to set ForwardAgent to 'no' when I connect with ssh:

    ssh -o ForwardAgent=no my_buildbot_slave_machine
    

    Indeed, by default ForwardAgent is set to "yes" in my ssh configuration. It means that the ssh keys of my own machine are used when I am connected to the slave machine, instead of those of the slave machine. When I disconnect, my own ssh keys are not available anymore and the problem appears.