In my daily work, I have to run scripts from User A and from User A it will sudo to User A1 and User A2 to run actions. Here I have to ensure that some parameters from User A can be inherited to A1 and A2 when issues the sudo commands.
Since environment variables can influence program behavior, sudoers provides a means to restrict which variables from the user’s environment are inherited by the command to be run. There are two distinct ways sudoers can deal with environment variables.
You can use /etc/sudoers file to define this kind of inherit activities. For instance I need to ensure user A can be inherited, I need to define below in the /etc/sudoers,
User_Alias SUDOING_USER = A
And then you can define detailed parameters as below,
env_keep = “PERL5LIB PATH”
Defaults:SUDOING_USER env_delete =”…”
Pls. note all of the operations have to be done from root user and /etc/sudoers is subject to change due to system maintenance.
More details, http://www.sudo.ws/sudoers.man.html