Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to use config files for use with sudo?

For example a .bashrc, .gitconfig, or an emacs init.el

Specifically I wanted to get LSCOLORS in sudo commands. I know that I can put these variables in the environment.

eg. in .bashrc:

export LSCOLORS = ...
alias sudo='sudo -E'

then run sudo

sudo ...

But I am wondering if there is another way to setup defaults for sudo.

share|improve this question
up vote 1 down vote accepted

You can define environment variables in the /etc/environment file, sudo will load them. This way, you don't need to use the -E parameter with sudo. Another approach is to avoid sudo resetting the environment by commenting out the line Defaults env_reset in the /etc/sudoers file. In this case you will have sudo preserve the current environment where it is called from. For further options see man sudoers.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.