Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need git user to run

chgrp -R www-data linode.git/
chmod -R 770 linode.git/

as root. Only these two commands and only for git user. How can I do that?

share|improve this question
up vote 2 down vote accepted

Add git to sudoers using visudo. The lines you should add will look something like this:

git hostname = (root) NOPASSWD: /bin/chgrp -R www-data /path/to/linode.git/, /bin/chmod -R 770 /path/to/linode.git/
share|improve this answer
    
I used joe to edit the sudoer file. I hope that's fine. When I run the chgrp command I get this error chgrp: changing group of linode.git/objects/pack': Operation not permitted`. If I run the comman as root it works. – Radek Nov 18 '10 at 0:53
    
@Radek: You should do EDITOR=joe sudo visudo. If you don't use visudo bad things could happen (see man visudo). Are you doing sudo -u git chgrp ... when logged in as yourself or sudo chgrp ... as the user "git"? In either case, you have to use sudo. – Dennis Williamson Nov 18 '10 at 3:00
    
@Dennis Williamson: if I copy the line you gave me into sudoers I get this error on saving. >>> /etc/sudoers: syntax error near line 18 <<< – Radek Nov 18 '10 at 3:20
    
strange but this one works git ALL=(root) NOPASSWD: /bin/chgrp – Radek Nov 18 '10 at 3:32
    
I strongly recommend using full paths for all file or directory references in the sudo string. E.g '/bin/chgrp -r www-data /var/local/linode.git/' – Slartibartfast Nov 18 '10 at 5:24

I recommend using super, a handy tool which is basically setuid but you can limit it to certain users or groups.
I'm actually using it for this exact purpose.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .