Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.