Working on a Java training environement, I was hurting myself on a simple issue: any command executed through the “sudo” admin passthrough was not successful due to leak of environement variables set into some of my specific files:
/etc/default/javaenvsetting #default value for the javaenvsettings, executed from ~/.bashrc file
/etc/skel/.javaenvsettings #default user values added to the user home when created
~/.javaenvsettings #user instance of the /etc/skel/.javaenvsettings file.
So, seeking the web for a solid solution, I’ve found an entry from stackoverflow explaining secret of the
in such path you can create any file, (with a chmod 0440) containing any sudo definition.
With the magical following command you will be abale to maintain some environement variables set for a connected user to the sudo environement.
Defaults env_keep +="JAVA_VERSION" Defaults env_keep +="ST_VERSION" Defaults env_keep +="MAVEN_VERSION" Defaults env_keep +="ECLIPSE_VERSION" Defaults env_keep +="INTELLIJ_VERSION" Defaults env_keep +="TOOLS_HOME" Defaults env_keep +="ECLIPSE_HOME"
Defaults env_keep +="INTELLIJ_HOME"Defaults env_keep +="M2_HOME" Defaults env_keep +="JAVA_HOME" Defaults env_keep +="PATH"
With such lines all those variables from user environement will be maintained (env_keep) to the sudo execution environement.
Any new user ?
for any newly created user, the previoulsy prensented files are added to the
.bashrc execution process, so environement variables are well set and usable.
That’s it !
Have fun !