我正在尝试为一个使用PHP构建的大学小组项目设置git开发工作流程。在过去的一周里,我一直在帮助团队中的每个成员配置他们的电脑,以便我们能够协作提交代码到主仓库。现在,每个开发人员都能够成功地在他们的机器和GitHub托管的远程仓库之间同步代码,无论他们使用哪个操作系统。
然后,我将这段PHP代码添加到hook调用的文件中:
现在,如果我从SSH终端会话中调用此代码,使用
经过数小时的谷歌搜索,每个问题都导致了另一个问题。我已经按照其他线程建议更改了文件所有者权限,但现在这是我从脚本输出(通过HTTP)得到的错误:
我猜测
遗憾的是,小组中没有其他人知道这种类型的事情,也没有任何好的设置指南。任何帮助/提示将非常感激!
更新:
VonC发布的指南似乎是我们需要做的合适解决方案。我尝试删除.ssh文件夹并按照该指南中的每个步骤精确执行,但现在我们得到以下错误,指出存在权限错误:
然后,我将这段PHP代码添加到hook调用的文件中:
<?php
$output = shell_exec('git pull origin master 2>&1');
echo "<pre>$output</pre>";
?>
现在,如果我从SSH终端会话中调用此代码,使用
php git_pull_post_hook.php
,最新更改(来自团队中的任何开发人员)将成功同步。但是,每当GitHub挂钩或其他人通过HTTP访问php文件时,什么也不会发生。经过数小时的谷歌搜索,每个问题都导致了另一个问题。我已经按照其他线程建议更改了文件所有者权限,但现在这是我从脚本输出(通过HTTP)得到的错误:
Could not create directory '/var/www/.ssh'.
Host key verification failed.
fatal: The remote end hung up unexpectedly
我猜测
www-data
没有足够的权限访问我们服务器根目录中的SSH密钥,这就是导致所有错误的原因...但实际上,/var/www/.ssh
目录确实存在于服务器上,所以我不明白出了什么问题。遗憾的是,小组中没有其他人知道这种类型的事情,也没有任何好的设置指南。任何帮助/提示将非常感激!
更新:
VonC发布的指南似乎是我们需要做的合适解决方案。我尝试删除.ssh文件夹并按照该指南中的每个步骤精确执行,但现在我们得到以下错误,指出存在权限错误:
No directory, logging in with HOME=/
root@xxx:~# mkdir /var/www/.ssh
root@xxx:~# chmod 0700 /var/www/.ssh
root@xxx:~# chown -R www-data:www-data /var/www/.ssh
root@xxx:~# su - www-data -c "ssh-keygen -t rsa"
No directory, logging in with HOME=/
Generating public/private rsa key pair.
Enter file in which to save the key (/var/www/.ssh/id_rsa):
Could not stat /var/www/.ssh: Permission denied
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
open /var/www/.ssh/id_rsa failed: Permission denied.
Saving the key failed: /var/www/.ssh/id_rsa.
root@xxx:~# chmod 0600 /var/www/.ssh/id_rsa
chmod: cannot access `/var/www/.ssh/id_rsa': No such file or directory
root@xxx:~# chmod 0600 /var/www/.ssh/id_rsa.pub
chmod: cannot access `/var/www/.ssh/id_rsa.pub': No such file or directory