I have a problem with running git pull from a php script on a remote server. I have looked at a lot of different sources to make it work but none works for me. So what have I done so far:
Created the pub and private key for Apache:
mkdir /var/www/.ssh
sudo chown -R apache:nobody /var/www/.ssh
su - apache -c "ssh-keygen -t rsa"
Then I have put my public key on Bitbucket.
Then I run the command:
sudo -u apache git pull
Everything works fine.
After all that I wrote a simple sh
script which I call from PHP
.
The .sh script:
#!/bin/sh
git pull
and the PHP script:
<?php
$cmd="./gitpullsc.sh 2>&1";
echo exec($cmd);
?>
I run the php script from a web browser and I get back this:
Permission denied (publickey).
fatal: Could not read from remote repository.Please make sure you have the correct access rights and the repository exists.
Then I tried to add to the script whoami
(to see if the user running the php script is the right one) and I get apache. So everything ok.
I use Red Hat linux.
UPDATE
Ok, maybe I found the problem, but still looking for the solution.
I run again the sudo -u apache git pull
and now I am getting asked for the private key passphrase again.
But if I run the command ssh-add -l
I get:
2048 ***thenumber** /var/www/.ssh/id_rsa (RSA)
So I think that everything is fine. But the problem maybe is that i run the ssh agent this way:
ssh-agent /bin/bash
UPDATE
Yes, the problem was really the passphrase prompt. I still don't know how to fix it, but for now I just left the passphrase blank and it works...
I answered a similar question. I really wanted to add a comment referring to that answer but I do not have enough points to add a comment.
The idea is use start ssh-agent once and load your keys to it. Later, in your .bashrc, you update environment variables so that it points to the same ssh-agent (that already has the keys).
Please look at trying to deploy using Capistrano but ssh-agent on my remote machine doesn't keep my identity loaded so the git command fails; why?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With