I'm trying to write simple post-recieve script, which would switch to webserver user and pull git repository. To do so, I added git user to sudoers (I've added this to very last line):
git ALL = (www:www) NOPASSWD: /usr/bin/git
but I still can't execute
sudo -u www git pull origin production
without password prompt.
www
user, correct? Also please runwhich git
to confirm that thegit
command actually points to/usr/bin/git
.which git
was used to get the git path (the path is correct). Why would I want to give sudo to www user? The post-recieve script will be executed by git user and I want git user to go to webserver folder and pull changes as www user.sudo -u www git pull origin production
says to rungit pull origin production
as the www user, so it seems like you're trying to give the www user sudo access. How come you need sudo? How about just trying:su -s /bin/bash -c '/usr/bin/git pull origin production' www
. Thats assuming your www user has a nologin shell and that your webserver folder is owned by www.usera@server$~: sudo -u userb some_command
allows usera run some_command as userb. You're command does very similar thing with one difference, it requests www's password instead of git's password. I need to avoid password prompt to use it in git post-receive script