4

I have main user, e.g. dave with home directory /home/dave. And it has lots of configs for various programs it can run like vim, bash etc. When I login as root user, all my configs are not used since root has separate home directory: /root.

I do not plan to have any other users on my machine. So does changing root user home directory to dave one have any disadvantages?

  • 1
    I believe I've install package(s) that put files in /root/; I'm guessing they weren't official packages, and whilst you could work your way around this pretty easily; I suspect it may cause problems down the road come release-upgrade time (even if I can't think of why... I'd opt for symlinks) – guiverc Jan 18 at 10:07
  • There is not 1 single good reason to use root over a normal user with admin permissions (ie. using sudo -i). And there is 1 big reason never to enable a root login: the safety of your data. – Rinzwind Jan 18 at 23:17
5

Yes, many.

  • Anything you run as root which modifies configuration or state in $HOME will update the contents of /home/dave, probably causing the modified files to end up owned by root, which in turn will make them impossible for you to modify without being root (which may break some programs (vim and most shells being prime examples, command history will end up only usable by root).
  • Anybody with write access to /home/dave can theoretically trivially run commands as root. Keep in mind that many CLI tools have startup files in $HOME that get run, not just parsed, when you start them. .bashrc and .vimrc are trivial examples, both of which allow anybody who can write to them to run arbitrary commands with the privileges of the user who executes bash or vim in a way that uses them.
  • Some things that might be in /root should not be readable by any other users for security reasons. The prime example is stuff like SSH or GPG keys, but there are others. Merging /root with another home directory makes it much harder to ensure these secrets stay secret. Note that this is why /root exists at all, old UNIX systems just used / as root's home directory, which leaked lots of info to other users.
  • Any misconfiguration in config files in /home/dave that makes it impossible for the dave user to log in will also make it impossible for the root user to log in. This makes any configuration changes much more risky.

Note that the second and third points are potentially serious security issues, even on a single user system. Always remember that any attack that manages to get the ability to run code as your user can do anything your user can do.

If your goal is to simply share configuration across the whole system, you can avoid all but the last issue above by using the configuration files under /etc instead of in home directories. These are the system-wide defaults for configuration, so modifying them modifies configuration for everyone on the system. Almost all interactive CLI tools that have some form of configuration that isn't inherently user-specific have configuration files under /etc.

1

I'd play it safe and add per-command redirects.

You can do this in 2 ways:

  • symlinking the config files one by one, for example for vim: sudo ln -s /home/dave/.viminfo /root/.viminfo
  • by prepending HOME=/home/dave to each command. You can create an alias in your .bashrc file so you don't have to think about it:
    echo "alias vim='HOME=/home/dave vim'" | sudo tee -a /root/.bashrc
    
  • I don't understand why anyone would run their text editor as root."sudo -e /etc/textfile" has the same length as "sudo vi /etc/textfile", but doesn't have the problem of running the editor under the root account – Ferrybig Jan 18 at 23:12
  • Thanks, I didn't know about the -e flag. To me, your first sentence comes across as arrogant and uninviting. To reach more readers, I suggest you move it to the end of your comment and make it softer. – Gogowitsch Jan 19 at 10:59
  • Sorry, I did not mean to be arrogant. I was just confused why you used an text editor as an example – Ferrybig Jan 19 at 11:54
0

If your aim is to edit files as root, simply use sudoedit (I believe it’s equivalent to sudo -e).

The command will open your editor on a temporary file which will replace the original on successful exit. (Vim’s :cquit command can be used to make exiting “fail.”)

As for the shell, I’d suggest leaving it barebones. It will remind you don’t want to be logged in as root for very long. If you must, use the /etc directories or other means of configuring root specifically. But do not link the files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.