mirroring a self-hosted git repository to github.com (auth failures)
Asked Answered
E

1

9

I am trying to have my personal server be my primary git remote and automatically mirror that to github. I found this article which gets it mostly working with a post-receive script that does git push --mirror (essentially).

My approach is different in that I would like to avoid having to create and secure a deploy key and then configure it on every repository.

My post-receive script works correctly with most of the variants below as marked in the comments except when I do the full nohup + stdio redirection + backgrounding as in the blog article above, the authentication stops working.

GITHUB_USERNAME=focusaurus
BARE_PATH=$(pwd -P)
REPO_NAME=$(basename "${BARE_PATH}")
REPO_URL="ssh://[email protected]/${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 & 

I have ssh agent forwarding which I believe is how the working versions work. So my question is why do those last 2 variations fail with authentication errors?

Excitor answered 27/10, 2013 at 17:48 Comment(5)
Are you sure the failure is caused by these changes, and not something else?Chatham
Yes. I have tested all those flavors above and as per the comments, the ones that are marked as "works OK" work reliably, and then just changing how stdio is handled consistently causes failure.Excitor
So it seems like the problem might be something in my ssh configuration. Investigating.Excitor
Have you tried nohup git push --mirror "${REPO_URL}" >/dev/null 2>&1 & ?Michaud
I just tried that variation now and it also fails. I think something's fishy with my ssh config or ssh agent forwarding somehow but git push -v doesn't seem to add any verbosity so I'm having trouble troubleshooting effectively.Excitor
R
1

Maybe you can try to set the verbose flag on ssh to figure out what is going wrong.

You can use the GIT_SSH environment variable to substitute the command that git will use to open the ssh connection. From the man page:

   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.

So a script in /tmp/verb-ssh that looks like:

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

and then setting the environment variable GIT_SSH=/tmp/verb-ssh should provide some useful debugging information.

Reiff answered 28/11, 2013 at 14:31 Comment(1)
Well, that's a great tip for getting some debug output. I am still unable to understand the root cause but I think I'm just going to KISS and leave the push to github in the foreground as it's usually quick anyway.Excitor

© 2022 - 2024 — McMap. All rights reserved.