[clue] sudo and sudoers: force changing working directory

Sean LeBlanc seanleblanc at comcast.net
Wed Oct 26 10:15:23 MDT 2011


Thanks for the suggestions, everyone. I ended up solving this by having 
the target script being run do the cd so that it's not something the 
user doing the sudo could muck up.


Cheers,
Sean


On 10/18/11 11:43 AM, chris fedde wrote:
> I typically make wrapper scripts for jobs that require average users
> to use sudo:
>
>      #!/bin/bash
>
>      user=mysql
>      if test $EUID -ne `id -u $user`
>      then
>          exec sudo -u $user $0 "$@"
>      fi
>
>      # stand in for real work
>      id
>
> On Mon, Oct 17, 2011 at 2:21 PM, Sean LeBlanc<seanleblanc at comcast.net>  wrote:
>> So, I want to be able to have a certain user sudo to a specific user and
>> run a specific command.
>>
>> Preferably, I'd like to NOT have to remember to change working directory
>> to the target user's home dir prior to running that specific command.
>>
>> I have always_set_home in sudoers as the default, but setting home is
>> not enough - working directory has to be changed.
>>
>> I thought I'd try out giving sudo the "-i" flag, but that then seems to
>> result in having to type in password, even though that is not desired
>> for this scenario.
>>
>> Any ideas on how to achieve this?
>>
>> right now, the command looks like this:
>>
>> sudo -u targetuser "cd /home/targetuser; thecommand"
>>
>>
>>
>> _______________________________________________
>> clue mailing list: clue at cluedenver.org
>> For information, account preferences, or to unsubscribe see:
>> http://cluedenver.org/mailman/listinfo/clue
>>
> _______________________________________________
> clue mailing list: clue at cluedenver.org
> For information, account preferences, or to unsubscribe see:
> http://cluedenver.org/mailman/listinfo/clue
>



More information about the clue mailing list