How let your root user use your main dotfiles


When you have a single-user system, or one with only one user with sudoer access, I always used to hate that every time I became root, I'd lose the settings set in my bashrc and aliases, my vimrc and preferred directory shortcuts. About 6 months ago, I had the crazy idea to change the root user's home directory from /root to /home/luke so root would look in my main directory for all its dotfiles.

I was initially worried that this could cause some vulnerabilities, it might still, but I have to say that it's been hugely convenient and hasn't given me any problems in all these months, so I recommend trying it out. All you have to do is open /etc/passwd and change the directory on the line starting with root: to your typical home directory.

So whenever you log in as root, you'll still have access to all your rc settings, and will be in your familiar home folder. I didn't think of it before, but you'll also have fewer log files to have to sort through. For example, if I once worked out a compilcated shell command and am trying to look it up in my .bash_history, I used to have to check /home/luke/.bash_history and /root/.bash_history if I couldn't remember if I ran it as myself or root. Now, however, both accounts use the same history file for bash, and also other programs.

So anyway, I recommend trying it out. I'm sure I'll get a couple emails about how it could be potentially dangerous, but the convenience has been huge and I've had no problems, although I might not recommend doing this on your webserver to hedge against unknown vulnerabilities.