将自托管的Git仓库镜像到github.com(身份验证失败)

9
我正在尝试将我的个人服务器作为主要的git远程仓库,并自动将其镜像到github。我找到了这篇文章,它使用一个post-receive脚本来实现大部分功能,该脚本执行git push --mirror(本质上是如此)。
我的方法与众不同,我想避免在每个存储库上创建和保护部署密钥,然后对其进行配置。
我的post-receive脚本正确地处理了下面大部分变体的注释标记,除了如上述博客文章中的完整的nohup + stdio重定向 + 后台处理方式,认证停止工作。
GITHUB_USERNAME=focusaurus
BARE_PATH=$(pwd -P)
REPO_NAME=$(basename "${BARE_PATH}")
REPO_URL="ssh://git@github.com/${GITHUB_USERNAME}/${REPO_NAME}"
echo "About to mirror to ${REPO_URL}"

#hmm, this works
#git push --mirror "${REPO_URL}"

#this works, too
#nohup git push --mirror "${REPO_URL}"

#and this also works OK
nohup git push --mirror "${REPO_URL}" &

#but this fails with
#Permission denied (publickey).
#fatal: The remote end hung up unexpectedly
#Somehow ssh agent forwarding must get screwed up? Help me, Internet.
#nohup git push --mirror "${REPO_URL}" &>>/tmp/mirror_to_github.log &

#this is the one used in the blog post above but it also fails
# nohup git push --mirror "${REPO_URL}" &>/dev/null & 

我有SSH代理转发,我相信这就是工作版本的原因。那么我的问题是,为什么最后两个变体会出现身份验证错误?


你确定故障是由这些更改引起的,而不是其他原因? - Robin Green
是的。我已经测试了上述所有版本,并根据评论,那些标记为“正常工作”的版本可靠地工作,而只是一致地更改stdio的处理方式会导致失败。 - Peter Lyons
所以看起来问题可能是我的ssh配置的问题。正在调查。 - Peter Lyons
你尝试过使用 nohup git push --mirror "${REPO_URL}" >/dev/null 2>&1 & 吗? - Eamonn O'Brien-Strain
我刚刚尝试了那个变化,但它也失败了。我认为我的ssh配置或ssh代理转发有些问题,但是git push -v似乎没有增加任何详细信息,所以我很难有效地进行故障排除。 - Peter Lyons
1个回答

1
也许你可以尝试在ssh上设置verbose标志来找出问题所在。
你可以使用GIT_SSH环境变量来替换git将用于打开ssh连接的命令。从man页面获取:
   GIT_SSH
       If this environment variable is set then git fetch and git push
       will use this command instead of ssh when they need to connect to a
       remote system. The $GIT_SSH command will be given exactly two
       arguments: the username@host (or just host) from the URL and the
       shell command to execute on that remote system.

       To pass options to the program that you want to list in GIT_SSH you
       will need to wrap the program and options into a shell script, then
       set GIT_SSH to refer to the shell script.

因此,位于/tmp/verb-ssh的脚本看起来像:

#!/bin/bash
/usr/bin/ssh -vvv "$@"

然后设置环境变量GIT_SSH=/tmp/verb-ssh,将提供一些有用的调试信息。


那是一个很好的获取调试输出的技巧。我仍然无法理解根本原因,但我想我只是要保持简单并将推送到Github放在前台,因为通常很快。 - Peter Lyons

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接