Home > Software engineering >  "sudo -u www-data git pull" Credential Saving?
"sudo -u www-data git pull" Credential Saving?

Time:04-08

I have my apache2 webserver directory as a Git directory, so when me and my team members (school project) make changes to our GitHub folder, it can easily be pulled by running 'git pull' in putty.

I want to make this automatic (using a WebHook) by having a "pull.php" file that has "<?php exec("git pull"); <?" inside it.

However, the user that shows up when I run whoami function in php is "www-data".
In order to allow www-data to run git pull without having to enter credentials (I tried setting up SSH and it refused to work), I need to allow them to store credentials.

This is problematic because unlike other users, www-data has no directory in /home/accountname to save its .gitconfig to.

How do I go about having "git credential.helper store" work for www-data?

I would also not mind having SSH, but I run into the same problem where the default directory to save the id_rsa file to says no permission/does not exist, so I would prefer the previous question to be answered.

CodePudding user response:

You have a similar issue in WordOps/WordOps #305

www-data user cannot write anything in /var/www because this directory's owner is root. So you can create the .gitconfig file as root, and then change owner and permissions (following this recommendation) with

chown www-data:www-data /var/www/.gitconfig
chmod 644 /var/www/.gitconfig.

Or you can change /var/www directory owner (chown www-data /var/www) to allow www-data to create files in this directory.

  • Related