I've set up a PHP script to perform a GitHub pull:
This is contained in my Github folder /home/mysite/public_html/github
github_pull.php
<?php
echo `git pull 2>&1`;
?>
My server does already have the SSH public key, as if I perform git pull
from Terminal:
ssh [email protected]
cd public_html/github
git pull
This works successfully (however I do have to enter the password for the rsa key first) Update: password is no longer needed (see comments)
However, when I run github_pull.php
I get the following error:
Permission denied (publickey). fatal: The remote end hung up unexpectedly
The SSH key is contained at /home/mysite/.ssh/id_rsa
When I run
<?php echo `whoami`;
It outputs mysite
As commented, try first an https url:
ssh [email protected]
cd public_html/github
git remote set-url origin https://github.com/username/reponame
git pull
This is far easier than tinkering with ssh keys, especially when they are passphrase protected.
If you must use ssh keys, then you must know the default location of the key is:
~/.ssh/id_rsa(.pub)
If the user executing the script is 'mysite
', then it will look for ~mysite/.ssh/id_rsa
.
And you need to make sure the ssh-agent
is running as mysite
user. Which is why it is easier at first to try it with a private key not passphrase-protected.
If your ssh key were to be somewhere else, then you would need a:
~mysite/.ssh/config
In that config file, as illustrated here, you can specify the location and name of the key you want to use.
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