<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> sudo su - {userid} -c "{command}"<br><br>This worked when the command was:<br> 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>> Date: Mon, 17 Oct 2011 14:21:03 -0600<br>> From: seanleblanc@comcast.net<br>> To: clue@cluedenver.org<br>> Subject: [clue] sudo and sudoers: force changing working directory<br>> <br>> So, I want to be able to have a certain user sudo to a specific user and <br>> run a specific command.<br>> <br>> Preferably, I'd like to NOT have to remember to change working directory <br>> to the target user's home dir prior to running that specific command.<br>> <br>> I have always_set_home in sudoers as the default, but setting home is <br>> not enough - working directory has to be changed.<br>> <br>> I thought I'd try out giving sudo the "-i" flag, but that then seems to <br>> result in having to type in password, even though that is not desired <br>> for this scenario.<br>> <br>> Any ideas on how to achieve this?<br>> <br>> right now, the command looks like this:<br>> <br>> sudo -u targetuser "cd /home/targetuser; thecommand"<br>> <br>> <br>> <br>> _______________________________________________<br>> clue mailing list: clue@cluedenver.org<br>> For information, account preferences, or to unsubscribe see:<br>> http://cluedenver.org/mailman/listinfo/clue<br></div>                                            </div></body>
</html>