0

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.

Constantin
  • 848
  • 8
  • 23
  • You set read permission for groups on `~/.ssh` and `sudo adduser {username} www-data` (or apache/httpd based on os) – Vinay May 07 '20 at 04:50
  • @Viney what I've understood from your comment is that the best practice says that I should add `www-data` to an user group, instead of assigning the directory to `www-data`? Basically what I did was `chown -R www-data /direcotry` – Constantin May 07 '20 at 05:02

0 Answers0