简体   繁体   English

php在没有sudo的情况下执行ssh git pull脚本(主机验证错误)

[英]Php execute ssh git pull script without sudo (host verification error)

What I am trying to do 我要做什么

I have a git repository on bitbucket. 我在bitbucket上有一个git存储库。 After pushing to the repository from my local machine I want to automatically pull the master branch to my webspace. 从本地计算机推送到存储库后,我想自动将master分支拉到我的网站空间。

What I have done so far 到目前为止我做了什么

I connected to my server using ssh, created the ssh key and registered the public key on github. 我使用ssh连接到服务器,创建了ssh密钥,并在github上注册了公共密钥。 I created a .sh script which pulls the master branch using ssh - so far so god - everything works when I run the script from the command line/putty 我创建了一个.sh脚本,该脚本使用ssh拉了master分支-到目前为止,天啊-当我从命令行/ putty运行脚本时,一切正常

What is the problem 问题是什么

I want to trigger the .sh script with a webhook on bitbucket (I can give an url). 我想用bitbucket上的webhook触发.sh脚本(我可以提供一个URL)。 For that purpose I created a .php file in my webspace: 为此,我在网站空间中创建了一个.php文件:

<?php
$output = shell_exec('./deploy.sh 2>&1');
echo $output;

my .sh script looks like this: 我的.sh脚本如下所示:

#!/bin/bash
git pull git@bitbucket.org:dualmeta/test.git master

As already said, running the .sh script with putty works perfectly fine. 如前所述,使用腻子运行.sh脚本可以很好地工作。 However if I enter the url to the .php file in my browser it gives me an error: 但是,如果我在浏览器中输入.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.

I already did some reserach and found that many people have the exact same problem. 我已经做了一些研究,发现很多人都遇到了同样的问题。 However in my case i do not have root/sudo access because it is a rented webspace and not my own vServer. 但是,就我而言,我没有root / sudo访问权限,因为它是租用的Web空间,而不是我自己的vServer。

Is there any chance getting this to work? 有机会使它起作用吗?

You must add access www-data or apache user to your git directory. 您必须将访问www-data或apache用户添加到git目录。

chown -R apache:apache git_directory

or 要么

chown -R www-data:www-data git_directory

or 要么

chmod o+rw -R git_directory

Use this too : 也使用这个:

git config credential.helper store

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM