简体   繁体   中英

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

What I am trying to do

I have a git repository on bitbucket. After pushing to the repository from my local machine I want to automatically pull the master branch to my webspace.

What I have done so far

I connected to my server using ssh, created the ssh key and registered the public key on 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

What is the problem

I want to trigger the .sh script with a webhook on bitbucket (I can give an url). For that purpose I created a .php file in my webspace:

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

my .sh script looks like this:

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

As already said, running the .sh script with putty works perfectly fine. However if I enter the url to the .php file in my browser it gives me an error:

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.

Is there any chance getting this to work?

You must add access www-data or apache user to your git directory.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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