Github hook bash 脚本未拉取
我在 EC2 服务器上设置了一个 github 帐户,没有出现任何问题。当我尝试运行 bash 脚本来“git pull”时,它不会这样做。我将执行“git status”和许多其他命令。这是我的 sh 文件
cd /var/www/html/TDS/;
ls -la;
type git;
git status;
git remote -v;
git pull origin master;
echo "hello world";
除了 git pull 之外的所有行都有效。我尝试过 git pull、git pull origin master、git fetch、git fetch origin master。我已经排除了所有可能性,例如权限问题和特权。
这个 sh 文件是通过点击 PHP 页面来执行的,PHP 页面看起来像这样
<?php
$output = shell_exec('/bin/sh /var/www/html/TDS/git.sh');
print_r("<pre>$output</pre>");
?>
非常简单,它可以在没有 Pull 请求的情况下工作。任何帮助都会很棒,我已经很接近让它发挥作用了。
I have a github account set up to my EC2 server with no issues. When i try to run a bash script to 'git pull' it wont do it. I will do a 'git status' and many other commands. Here is my sh file
cd /var/www/html/TDS/;
ls -la;
type git;
git status;
git remote -v;
git pull origin master;
echo "hello world";
All lines work except the git pull. I have tried git pull, git pull origin master, git fetch, git fetch origin master. I have ruled out all possibilities like permission issues and privileges.
This sh file is executed by hitting a PHP page, the PHP page looks like this
<?php
$output = shell_exec('/bin/sh /var/www/html/TDS/git.sh');
print_r("<pre>$output</pre>");
?>
Very simple and it works minus the Pull request. Any help would be amazing, I'm so close to getting this to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要使
git pull
正常工作,运行它的用户必须对 git 存储库的索引(在.git/
下)具有写入权限。确保运行脚本的用户(Apache?)拥有这些权限。For a
git pull
to work, the user running it must have write permissions to the git repo's index (under.git/
). Make sure the user under which the script is run (Apache?) has those rights....PHP(www-data)有权限吗?它是文件的所有者吗?
...does PHP (www-data) have permissions? Is it the owner of the file?
这是原始存储库的 ssh URL 吗?手动执行时是否有 ssh-agent 正在运行?您是否提供了对 shell 脚本的 ssh 代理访问权限(提示,答案是“是”、“是”、“否”。可能。)
因此我们确定问题出在 ssh 访问上。然后,您有两个选择:将 ssh-agent 凭据获取到 php 进程,并允许 php 脚本无需密码即可访问 ssh 凭据。两者都以某种方式存在问题。
要将 assh-agent 凭据获取到 php 进程,请将 $SSH_AUTH_SOCK 环境变量从 shell 复制到 php/shell 脚本
SSH_AUTH_SOCK=/tmp/ssh-wScioBA10361/agent.10361 git pull
。然后假设 php 脚本有足够的权限来访问该文件, git pull 将起作用。这是有问题的,因为您需要 ssh 进入系统以获取身份验证套接字,更改程序以使用新套接字(或编写程序来查找当前套接字),然后让一切保持运行。注销、重新启动等,您将失去 git pull 功能。另一个选项是为运行 git pull 的 php/shell 用户创建 ssh 凭据。找到主目录,为该用户创建 .ssh 和 ssh-keygen 新密钥。您可以将私钥设置为没有密码,以便任何可以访问此文件(安全风险!!)的人都可以使用这些凭据进行 ssh。将公钥添加到有权访问 git 存储库的帐户的授权密钥中(gitolite 将允许您限制该帐户可能拥有的权限)。
Is this an ssh URL to the origin repository? Do you have ssh-agent running when you do it manually? Have you provided ssh agent access to the shell script (hint, the answers are Yes, Yes, No. Probably.)
So we have determined it is ssh access that is the problem. You then have two choices: getting ssh-agent credentials into the php process and allowing the php script access to ssh credentials without requiring a password. Both are problematic one way or another.
To get assh-agent credentials into the php process, copy the $SSH_AUTH_SOCK environmental variable from a shell into your php/shell script
SSH_AUTH_SOCK=/tmp/ssh-wScioBA10361/agent.10361 git pull
. Then assuming the php script has sufficient privs to access that file, git pull will work. This is problematic because you need to ssh into the system to get the auth sock, change the program to use the new socket (or write a program to find the current socket), and leave everything running. Log out, reboot, etc and you will lose git pull functionality.The other option is to create ssh credentials for the php/shell user who is running
git pull
. Find the home directory, create .ssh, and ssh-keygen new keys for that user. You can set up the private key to not have a password so that anyone who can access this file (security risk!!) can ssh using those credentials. Add the public key to the authorized keys of the account who has access to the git repo (gitolite would allow you to restrict what privileges that account might have).