I have read this thread for properly setting up credentials caching.
All working smoothly, until I felt the need of setting up a GitHub Webhook.
So I have placed a script under /bash_scripts/..
folder which is correctly assigned to www-data
recursively.
ls -l
output:
drwxr-xr-x 2 www-data root 4096 May 7 01:31 bash_scripts
And this is the content of one of the bash
scripts for performing pull
#!/bin/bash
cd /var/www/beta && git pull origin master
Then, I have a PHP endpoint calling shell_execute on the above script:
PHP> shell_exec('/bash_scripts/beta-github-hook.sh');
And I've been banging my head for an hours or so trying to find out why it wasn't being executed. The reason?
Credentials for GitHub Repository access are not stored for the user www-data
. This is the command I've used to replicate the shell_exec
on the terminal in order to get the output to the issue:
root@vps806928:/# su --shell /bash_scripts/beta-github-hook.sh www-data
Username for 'https://github.com':
On the other hand, if I execute the script as root
, git uses the stored credentials:
root@vps806928:/# /bash_scripts/beta-github-hook.sh
From https://github.com/redacted
* branch master -> FETCH_HEAD
Already up to date.
root@vps806928:/#
How can I make Git store credentials for www-data
?
EDIT
The only workaround I found was editing the bash script and explicitly writing down the password for the repository to pull from:
git pull https://user:passwd@github.com/user/repo.git master
Although this is a workaround I'm still seeking for an answer to issue in question.