Reputation: 790
I have a server with a gitlab clone. I have set up everything, and it works, but now I want to do a git pull automatically. I already added a ssh key based on this:
https://help.github.com/articles/generating-ssh-keys/
If I run the command git pull
through putty, it works.
Now I want to create a php file which does an automatic git pull. I do that like this:
<?php
echo shell_exec( 'git pull 2>&1' );
?>
That gives the following error:
Host key verification failed. fatal: The remote end hung up unexpectedly
I have searched for a solution, and most things I found were problems with the ssh key. It does work when I run the command from the root user though. I changed the owner of my php file to root.
I am completely new to this, so I might miss something obvious. However, it is working when I execute git pull from the command line, and not when I call the php script and I have no idea how to fix this.
Upvotes: 0
Views: 2257
Reputation: 1634
This blog post may help, the main points it suggests are:
Creating the php script like this:
<?php
...
echo shell_exec("/full/path/to/bin/git pull 2>&1");
...
Note: You can find the path to your (Linux) Git installation by executing which git
Then doing an initial Git pull with the apache user to make sure the remote is added to the user's known_hosts
file like this:
sudo -u www git pull
Upvotes: 1
Reputation: 3828
While similarly named, this error has to do with the "Host Key" instead of the key used for public key authentication. This error most likely means that the host key (of the remote git server) has changed since it was stored in the known_hosts
file.
Check the key stored in the the .ssh/known_hosts
file of the user under which php runs (httpd? apache?). To fix the error, remove the line which corresponds with the hostname or ip of the remote git server. (From a security standpoint, you should verify the new "Host Key" before accepting it.)
Upvotes: 2