Ubuntu – Why is a user with root privileges not in ~ anymore

rootsudo

Just out of curiosity, I would like to know why, when I log in as root, I am not in /home/user anymore. What's the reason and what does /root directory do exactly?

I'm not an advanced user. Please answer in simple words or give a link that provides clear-cut, simple explanations. I use Ubuntu 16.04 and I log in as root by sudo -i. As it's explained here, sudo -i has /root as home. I want to know what the reason is; is there any advantage to be there? And not in ~ like the user of sudo -s.

Best Answer

You are not logging as root by running a sudo command. You are starting a shell with root privileges.

If you want to stay in the current user home directory, you can use sudo -s instead of sudo -i command.

cd ~ will take you to the same directory as if you are not in a shell with root privileges. Literally /home/$USER.

When you use sudo -i, the system acts as if you are logged in as root user. Because of this

cd ~ 

brings you to the root user home directory that is /root.

/root directory is a home directory for the root user.

The main difference is that shell settings files like .bashrc are used from /root in case of sudo -i, and from a normal user in case of sudo -s.

Related Question