I have a setup where there are two users on my Linux server: alice and bob. Alice has a clone of a shared bare repository that is in Bob's home folder. I have a hook on the bare repo in Bob's home folder that needs to be run as the user bob, but when Alice pushes to the bare, the hook is run as alice. Is there a way to make git run the hook as Bob without Alice needing Bob's password?
CodePudding user response:
Thanks to phd's comment, I was able to get a working solution. I created a script that does what the hook is supposed to do and, after adding
alice ALL=(bob) NOPASSWD: /absolute/path/to/script
to my sudoers file using
visudo
I let the hook run the command
sudo -u bob /absolute/path/to/script
which runs the script as bob.