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.

  • You are giving sudo permissions to the git user, but it sounds like you want to give sudo permissions to the www user, correct? Also please run which git to confirm that the git command actually points to /usr/bin/git.
    – Banjer
    Feb 12, 2013 at 15:14
  • 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.
    – Ficik
    Feb 12, 2013 at 15:23
  • the command sudo -u www git pull origin production says to run git 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.
    – Banjer
    Feb 12, 2013 at 16:02
  • 2
    AFAIK 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
    – Ficik
    Feb 12, 2013 at 16:15
  • 1
    Well, problem solved and I fell really dumb. The password prompt triggered git not sudo. For some reason www's key was removed from git server yesterday. At least I learned a bit about sudoers file. Anyway, thanks for your support
    – Ficik
    Feb 12, 2013 at 17:33


You must log in to answer this question.

Browse other questions tagged .