<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
How about:<br>&nbsp; &nbsp; sudo su - {userid} -c "{command}"<br><br>This worked when the command was:<br>&nbsp;&nbsp; sudo su - carl -c "ls -l"<br><br>The magic is in the dash after the su that tells it to use that users environment.<br>This may have security implications depending on your environment.<br><br>Carl<br><br><br><br><br><div>&gt; Date: Mon, 17 Oct 2011 14:21:03 -0600<br>&gt; From: seanleblanc@comcast.net<br>&gt; To: clue@cluedenver.org<br>&gt; Subject: [clue] sudo and sudoers: force changing working directory<br>&gt; <br>&gt; So, I want to be able to have a certain user sudo to a specific user and <br>&gt; run a specific command.<br>&gt; <br>&gt; Preferably, I'd like to NOT have to remember to change working directory <br>&gt; to the target user's home dir prior to running that specific command.<br>&gt; <br>&gt; I have always_set_home in sudoers as the default, but setting home is <br>&gt; not enough - working directory has to be changed.<br>&gt; <br>&gt; I thought I'd try out giving sudo the "-i" flag, but that then seems to <br>&gt; result in having to type in password, even though that is not desired <br>&gt; for this scenario.<br>&gt; <br>&gt; Any ideas on how to achieve this?<br>&gt; <br>&gt; right now, the command looks like this:<br>&gt; <br>&gt; sudo -u targetuser "cd /home/targetuser; thecommand"<br>&gt; <br>&gt; <br>&gt; <br>&gt; _______________________________________________<br>&gt; clue mailing list: clue@cluedenver.org<br>&gt; For information, account preferences, or to unsubscribe see:<br>&gt; http://cluedenver.org/mailman/listinfo/clue<br></div>                                               </div></body>
</html>