Git auto-deploy from Webhook giving permissions error?

February 26, 2019 276 views
Git Ubuntu

Hi all. I have an Ubuntu server which I want to update whenever new code is pushed to a remote repository. I can successfully run a "git pull" from the command line when I Putty into the server and am at the file location. I have code working to verify the secret key is correct, but I can't seem to get the code to execute "git pull" successfully. It returns the following error:
"error: cannot open .git/FETCH_HEAD: Permission denied"

This makes me think that the "user" (the script being run) doesn't have permission to access git? Because I can manually run "git pull" from the directory in Putty successfully, but when using PHP and putting shell_exec('git pull'), it returns that error.

I assume the solution needs to involve setting user permissions in the line before calling git pull. But I'm unsure what this shell snippet code should be.

Thanks every much for your help, I'm brand new to Digital ocean, and cloud computing in general.

1 Answer

Hey friend,

It sounds like you're running as a privileged user (not root) and executing a git pull on files that the user does not have access to. You could probably just make the user a sudo user and toss a sudo in front of the git pull. There are other ways to do it but it depends on your user/group setup.

https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart

Jarland

by Mitchell Anicas
The sudo command provides a mechanism for granting administrator privileges, ordinarily only available to the root user, to normal users. This guide will show you the easiest way to create a new user with sudo access on Ubuntu, without having to modify your server's sudoers file.
Have another answer? Share your knowledge.