[clue] sudo and sudoers: force changing working directory

CARL WAGNER carlewagner at msn.com
Mon Oct 17 16:19:29 MDT 2011


How about:
    sudo su - {userid} -c "{command}"

This worked when the command was:
   sudo su - carl -c "ls -l"

The magic is in the dash after the su that tells it to use that users environment.
This may have security implications depending on your environment.

Carl




> Date: Mon, 17 Oct 2011 14:21:03 -0600
> From: seanleblanc at comcast.net
> To: clue at cluedenver.org
> Subject: [clue] sudo and sudoers: force changing working directory
> 
> 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
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cluedenver.org/pipermail/clue/attachments/20111017/1a796085/attachment.html 


More information about the clue mailing list