Pet*_*ons 9 git github ssh-agent
我想让我的个人服务器成为我的主要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 &
Run Code Online (Sandbox Code Playgroud)
我有ssh代理转发,我相信工作版本的工作方式.所以我的问题是为什么最后2个变种因认证错误而失败?
也许您可以尝试在 ssh 上设置详细标志来找出问题所在。
您可以使用GIT_SSH
环境变量来替换 git 用于打开 ssh 连接的命令。从手册页:
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.
Run Code Online (Sandbox Code Playgroud)
所以其中的脚本/tmp/verb-ssh
如下所示:
#!/bin/bash
/usr/bin/ssh -vvv "$@"
Run Code Online (Sandbox Code Playgroud)
然后设置环境变量GIT_SSH=/tmp/verb-ssh
应该提供一些有用的调试信息。