I am running Debian. The default /root/.bashrc is kinda empty. So if I do sudo -i to login as root, there are many things are not setup properly. Normally, I just do the following:
$ sudo -i
# mv .bashrc .bashrc.bak
# ln -s /home/user/.bashrc . # or cp /home/user/.bashrc .
Note: the /home/user/.bashrc is the default one created by debian useradd without any custom modification.
So Now, I just want to clarify if this is safe to do. I am just lazy to create another .bashrc file for root.
By doing this you are effectively making the root account only as secure as your own "user" account. This means that any browser-based trojan or other successful attack on your account is implicitly able to gain root access too.
Is this acceptable to you?
If not, don't symlink the files; copy it once you have verified the content is what you expect.
I don't think it's a good idea generally, not only in Debian, for at least 2 reasons.
First, you should be very very careful and apart from copying user's .bashrc you should also copy all other files that are sourced by it which might referred to as ~/.bash_aliases etc. or you risk some errors and possible undefined behavior. For example, what if, for whatever reasons, you have this in your .bashrc or one of the scripts sourced by it:
. FILE2
echo "$var1"
echo rm -fr "$var1"/*
When root runs its ~/.bashrc and FILE2 is missing then it would start removing the entire filesystem.
Second, you shouldn't work as root for too long because it's very
risky. And you should be always immediately able to say if you're
root or a regular user in the current interactive subshell. It's most
commonly done by changing the final
character of prompt to
#
when
running as
root
[1]
so at least PS1 setting should be different between root and
non-root .bashrc.
So effectively you are using only one .bashrc for root and normal users.
Is this safe (for the root account), you ask?
Well, take a look at your ~/.bashrc if there is code inside that might harm root, if so apply it only to normal users by enclosing this code with e.g. if [ "$(id -u)" -ne 0 ]; then ... .
Then do the same the other way 'round: if something is in original /root/.bashrc that must be set for root but not for normal users, copy this code and enclose it with [ "$(id -u)" -eq 0 ].
This way you could have one .bashrc that fits them all.
sudo ls dir,sudo ls dir/dir/everytime. It's easier to usesudo -iandls. that's all. The only reason I use root user is to makelseasier. Cheers. - sgon00