Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding sudo -E

Tags:

sudo

I wish to run TOMCAT with my current user's permissions, not the root's environment variables.

vagrant@dev:~/Workspace/eurekastreams$ echo $JAVA_OPTS
-Xmx1024m -XX:MaxPermSize=128m -Dlog.home=/home/vagrant/Workspace/software/

I tried, vagrant$>sudo -E /etc/init.d/tomcat7 start.

However, my software is not logging to the /home/vagrant/Workspace/software directory, which means, I believe, that the JAVA_OPTS environment variable was not set.

Am I understanding sudo -E correctly that it will perform a command with env vars of the current user?

like image 642
Kevin Meredith Avatar asked Apr 30 '26 15:04

Kevin Meredith


2 Answers

From man sudo :

-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing 
environment variables. The security policy may return an error if the user does 
not have permission to preserve the environment.

Thus yes, the -E will execute the command with the current environment variables.

like image 80
mazs Avatar answered May 02 '26 05:05

mazs


Unless you use the -u parameter with sudo, it will run your command as root. How about this:

sudo -u yourusername -l /etc/init.d/tomcat7 start

-u username : run the command as specified user -l : make it a login shell, reading starup scripts such as .bashrc, which, I assume, is where you set your environment variables.

like image 26
Tuncay Göncüoğlu Avatar answered May 02 '26 03:05

Tuncay Göncüoğlu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!