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.
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.
I know this is old, but in case anyone googles this and finds it.... Configure your own .bashrc as you like (~/.bashrc) Then when you need to use sudo, do it like...
sudo -E command
-E tells the superuser to preserve the current environment
Depending on what you want to do, it may be sufficient to set an environment variable in an alias for
sudo
. In my case, I was trying to set a different prompt for when I usesudo -s
to get a root shell. The following alias in my.bashrc
seems to work perfectly: