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?

link|improve this question

feedback

2 Answers

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/
link|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
show 1 more comment
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.