2013-10-27 56 views
9

我想讓我的個人服務器成爲我的主要git遠程鏡像並自動將其鏡像到github。我找到了this article,它主要用於(本質上)的post-receive腳本。將自己託管的git存儲庫鏡像到github.com(auth失敗)

我的方法不同之處在於我希望避免必須創建和保護部署密鑰,然後在每個存儲庫上對其進行配置。

我的post-receive腳本在下面的大部分變體中都可以正常工作,除非我在上面的博客文章中完成nohup + stdio重定向+背景時,身份驗證停止工作。

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 & 

我有ssh代理轉發,我相信是工作版本的工作方式。所以我的問題是爲什麼最後2個變體會失敗並出現身份驗證錯誤?

+0

你確定失敗是由這些改變引起的,而不是其他的嗎? –

+0

是的。我已經測試了上述所有風格,並根據評論,被標記爲「可以正常工作」的那些可靠工作,然後只是改變stdio的處理方式一直導致失敗。 –

+0

所以它看起來像這個問題可能是我的SSH配置中的東西。調查。 –

回答

1

也許你可以嘗試在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 [email protected] (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 "[email protected]" 

,然後設置環境變量GIT_SSH=/tmp/verb-ssh應該提供一些有用的調試信息。

+0

那麼,這對於獲得一些調試輸出是一個很好的提示。我仍然無法理解根本原因,但我認爲我只是要去KISS,並把github推到前臺,因爲無論如何它通常很快。 –

相關問題