[英]Php execute ssh git pull script without sudo (host verification error)
我要做什么
我在bitbucket上有一个git存储库。 从本地计算机推送到存储库后,我想自动将master分支拉到我的网站空间。
到目前为止我做了什么
我使用ssh连接到服务器,创建了ssh密钥,并在github上注册了公共密钥。 我创建了一个.sh脚本,该脚本使用ssh拉了master分支-到目前为止,天啊-当我从命令行/ putty运行脚本时,一切正常
问题是什么
我想用bitbucket上的webhook触发.sh脚本(我可以提供一个URL)。 为此,我在网站空间中创建了一个.php文件:
<?php
$output = shell_exec('./deploy.sh 2>&1');
echo $output;
我的.sh脚本如下所示:
#!/bin/bash
git pull git@bitbucket.org:dualmeta/test.git master
如前所述,使用腻子运行.sh脚本可以很好地工作。 但是,如果我在浏览器中输入.php文件的网址,则会出现错误:
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我已经做了一些研究,发现很多人都遇到了同样的问题。 但是,就我而言,我没有root / sudo访问权限,因为它是租用的Web空间,而不是我自己的vServer。
有机会使它起作用吗?
您必须将访问www-data或apache用户添加到git目录。
chown -R apache:apache git_directory
要么
chown -R www-data:www-data git_directory
要么
chmod o+rw -R git_directory
也使用这个:
git config credential.helper store
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.