git ls-remote 在注销时失败

git ls-remote fails when logged out

我在使用“git 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.

在尝试使用buildbot时出现,不知如何解决

我设法用一个简单的脚本模拟了这个问题 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

我运行这个脚本使用屏幕。 它在我登录时有效:

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

然后,我注销...等待几秒钟,然后再次登录。 git ls-remote 命令失败。 在此示例中,我在第 13 次迭代后注销:

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.

你知道如何解决这个问题吗?

非常感谢!

听起来您不是使用 launchd 启动 buildbot 实例,而是使用 terminal/ssh 连接。有帮助 page "A buildbot process which is not started through launchd may not work properly. Worse yet, some of these authorities will be available to a process started in an ssh session, but will go away once you log out of that ssh session."

非常感谢您的帮助。

我终于找到了解决问题的方法。 当我连接 ssh:

时,我必须将 ForwardAgent 设置为 'no'
ssh -o ForwardAgent=no my_buildbot_slave_machine

的确,在我的 ssh 配置中,默认情况下 ForwardAgent 设置为 "yes"。意思是我连接slave机器的时候用的是我自己机器的ssh key,而不是slave机器的。当我断开连接时,我自己的 ssh 密钥不再可用,问题就出现了。