所以我在私有(private)服务器的远程存储库中有一个接收后脚本。我想要的是每次远程 repo 收到推送时执行到 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 内的一个私有(private)repo。
我可以在远程服务器上的 repo 中执行手动推送,因为我已经添加了 SSH key ,所以 ssh 身份验证工作正常。但是,如果我尝试从 post-receive 钩子(Hook)中推送,它突然就不起作用了。这是我得到的错误
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.
任何帮助,将不胜感激。
最佳答案
if I try to run the command as sudo it shows an error
这意味着 root 没有相同的
~user/.ssh/id_rsa(.pub)
允许用户通过适当的身份验证访问 GitHub 的私钥/公钥。但是,如果该脚本打算以 root 身份运行,这意味着您可以以用户身份运行该特定命令
sudo -S -u otheruser ....
如the OP comments :
However, I need to change sudoers file so I allow that user to perform
sudo
commands without typing their password.
关于git - 在 post-receive Hook 内执行推送到 github,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45174465/