ChristianWagner
ChristianWagner

Reputation: 49

"sudo -u www-data git pull" Credential Saving?

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.

EDIT: In the end it was a variety of problems. it was trying to pull using HTTPS because i cloned it using HTTPS. long story short, i ended up deleting the repo and recloning it with SSH and all of my problems went away. There were a lot of steps in between but anyone with a similar problem can just do that and skip the headache haha.

Upvotes: 3

Views: 1657

Answers (1)

VonC
VonC

Reputation: 1323963

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.

The OP ChristianWagner confirms that cloning the repository with SSH instead of HTTPS allows for the git pull to work.

Upvotes: 1

Related Questions