Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nepsilon/576d13f05ce207c49becb52af022b6a8 to your computer and use it in GitHub Desktop.
Save nepsilon/576d13f05ce207c49becb52af022b6a8 to your computer and use it in GitHub Desktop.
How to preserve user environment when using sudo? — First published in fullweb.io issue #102

How to preserve user environment when using sudo?

By Fabien Loudet, Senior SysOps at Rosetta Stone

Say you want to execute a command with elevated privileges (root), but also want to keep your environment variables (HTTP_PROXY for instance).

sudo offers this feature through its -E option, from the manpage:

-E   The -E (preserve environment) option indicates to the 
     security policy that the user wishes to preserve their
     existing environment variables.
     The security policy may return an error 
     if the -E option is specified and the
     user does not have permission to preserve the environment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment