【发布时间】:2017-07-18 18:27:57
【问题描述】:
所以我在私人服务器的远程存储库中有一个接收后脚本。我想要的是每次远程仓库收到推送时向 github 执行推送。我这样做是为了它可以首先通过一些安全检查,例如确保它们不会更改 master 分支中的内容等。
这是脚本:
#!/bin/sh
git --work-tree=/var/www/html/beta --git-dir=/var/repo/beta.git checkout -f
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
git push git@github.com:kevuno/mycoolrepo.git $current_branch
我的 coolrepo 是 GitHub 内的私有仓库。
我可以在远程服务器上的 repo 中执行手动推送,因为我已经添加了 SSH 密钥,所以 ssh 身份验证工作正常。但是,如果我尝试从 post-receive 钩子中推送,它突然就不起作用了。这是我得到的错误
remote: Host key verification failed.
remote: fatal: Could not read from remote repository.
remote:
remote: Please make sure you have the correct access rights
remote: and the repository exists.
任何帮助将不胜感激。
【问题讨论】:
-
您的 ssh 挂钩可能不会以您的用户身份运行
-
是的,似乎代码是以推送用户的身份运行的。我必须弄清楚这一点,因为如果我尝试以 sudo 身份运行命令,它会显示错误