[sudo-users] Force sudo to source environment file before running a command.

Techie techchavez at gmail.com
Tue Oct 20 14:51:03 EDT 2009


Thanks for the information. When you say bash style environment files
I assume yo uare referencing my prefixing variable statements with
"export".

If that is the case will Bourne shell style statements work inside
environment files such as..

FAVCOLOR=red
DOG=boxer

I am using RHEL and the latest RPM is for 1.69..and currently I am on 1.68
So if I can use environment files with 1.68 and bourne style that is acceptable.

Thanks again

On Tue, Oct 20, 2009 at 9:10 AM, Todd C. Miller
<Todd.Miller at courtesan.com> wrote:
> In message <dc3ecf560910200731g698f4dcdua4ae6a954c7ede3c at mail.gmail.com>
>        so spake Techie (techchavez):
>
>> Is it possible to force sudo to source a users environment file or any
>> environment file with "env_file" while running a command.
>> I have set a User_alias, Runas_Alias, Cmnd_Alias, and user privilege
>> for a user as follows.
>>
>> User_Alias TSTU = techie
>> Runas_Alias TSTA = operator
>> Cmnd_Alias TSTCMD = <commands to run>
>>
>> TSTU ALL = (root) TSTCMD, (TSTA) <commands that need environment>
>>
>> So all the commands defined in the TSTCMD Cmnd_Alias will be run as
>> root.. However for the commands run by the TSTA Runas_Alias AKA the
>> operator user...I need to source an environment file. This file is a
>> bash style environment file with statements like.
>>
>> export FAVCOLOR=red
>> export DOG=boxer
>>
>> Can I use the env_file parameter to accomplish this?  If so please
>> provide a syntax example. From the manpage it says it is possible but
>> no example.
>
> If what you want is to have env_file apply to any command run as
> TSTA, then this should do it:
>
> Defaults>TSTA env_file=/path/to/env/file
> TSTU ALL = (root) TSTCMD, (TSTA) <commands that need environment>
>
> If you want to apply env_file to the commands themselves,
> regardless of who they are running as:
>
> Cmnd_Alias TSTACMD = <commands that need environment>
> Defaults!TSTACMD env_file=/path/to/env/file
>
> TSTU ALL = (root) TSTCMD, (TSTA) TSTACMD
>
> In all cases you need to be running sudo 1.7.2 to support bash-style
> environment files.
>
>  - todd
>



More information about the sudo-users mailing list