Why is a user with root privileges not in ~ anymore?

The reason why the home of the root user is /root and not /home/root is because usually /home is a mount point to a separate partition/volume/disk... (for various reasons, such as disk space, or remote, ...)

If for some reason mounting /home would fail, you could still connect as root and be in your /root home directory to investigate and fix things

Moreover, for maintenance, initial setup, resizing, ... you would be connected as root and should be able to unmount/remount /home


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.


The Linux filesystem is structured in a specific way. Essential binaries are in /bin/, boot loader files are in /boot/, most device files are in /dev/, mount points for removable media are in /media/, etc...

See https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard.

Some minor details may differ from distro to distro (e.g. /usr/bin/ vs. /usr/local/bin/), but in general almost all Linux distros follow the same directory structure.

To answer your question:

The users' home directories are in /home/. In principle, Linux is a multi user operating system. You may just have one user account on your laptop with its home directory in /home/<username>/, but if you look into /home/ on a shared Linux server, you will see many home directories: one for each user account. The idea is that every user of the system has write permissions only in their own home directory. If your username is bob you can read and write and delete files in /home/bob/ but you cannot touch anything in /home/alice/ or in /var/log/.

root is different though. root is the administrative user and has write privileges everywhere on the system (and can act as any user of the system). So it makes sense that root has the special home directory /root/ because root is not a regular user. Other than that, /root/ is just a regular directory with no special magic, although it is quiet possible (even likely) that system utilities rely on /root/ being the home of user root.

When you execute sudo -i in a terminal, you switch from being e.g. the regular user bob to being root. Note that this switch affects only the terminal window where you typed sudo -i. For your file manager you are still bob and if you open another terminal window you are still bob in there. In this context the symbol ~ is a shorthand for the current user's home directory. For bob ~ means /home/bob/ but for root ~ means /root/.

I hope that clarifies things for you.

Tags:

Sudo

Root