Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there any way to make sudo use the user's .bashrc file instead of the root one? I would like to use my own .bashrc while using sudo instead of the one of root or /etc/bashrc (I would have to force other users to use it).

The man page doesn't help much, but I'm sure there is a way to do so.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I don't know if that is a very good idea, although I can imagine it to be handy: Inside your sudo environment, you will have the SUDO_USER environment variable set to the name of the user who called sudo. That variable can be used in your /root/.bashrc to achieve what you want.

Beware, however, that security-wise this can be quite delicate. You should think twice if this cannot somehow be exploited by an untrusted user.

share|improve this answer
I would prefer avoiding to modify the /root/.bashrc, but I still can't find any other solution than yours. Ok, then, I will proceed this way. Thanks for your answer! –  philippe Jun 6 '12 at 7:38

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.