Fix: root User’s Home Directory is /root

You might have noticed an error where typing cd or cd ~ takes you to /root instead of something inside of the /home directory that seems to hold home directories. If you’re getting this error, then you’ve probably noticed it every single time you’re operating as the super user in Linux. Fixing it is very simple because it actually isn’t an error at all.

Rather, this is caused by a peculiarity of how Linux handles the placement of the home directory. While an expected behavior, it can still be extremely confusing if you’ve never come across it before.

If you type the commands cd or cd ~ from the terminal, then you’ll be taken back to your home directory no matter where you are in the Linux directory hierarchy. This is true even if you’re on a separate partition or even an entirely different external file structure altogether. If you ever loose your place while climbing directories, then simply typing cd will take you right to where you more than likely started the moment you opened up your terminal.

On Linux, the root user’s home directory is /home/root on some select distributions, but you’ll usually see it positioned at /root right in the top level of the beginning of the file structure. While it’s configurable, this is the situation in the overwhelming majority of Linux distributions. Try typing the command cd /root as a regular user at the terminal. You’ll receive an error that reads “bash: cd /root: Permission denied” because this is the super user’s home directory.

Now that you’ve done this, open up a graphical root terminal window by typing gksu x-terminal-emulator at the terminal. You’ll be given a prompt that asks for your administrative password, because this instantiates a fully elevated command prompt.

Many Linux distributions, particularly those based on Ubuntu, hash out the root user’s name so you can’t log in as them. If you’re getting this kind of error on Ubuntu or another similar distribution, then this command will still get you logged in as root without worrying about this hash system. Regardless, this will open up a separate terminal window from the one you’ve been working in.

As soon as you’re at the bash prompt, type the command whoami; cd; pwd and push the enter key. This first identifies who you’re logged in as, then it changes to the home directory of the current user. You’ll notice that you’re logged in as the root user and the home directory of said user is not /home/root but instead /root itself. Linux distributions do this because some people like to install the entire /home directory on a separate partition from the top-level / mount point.

When you’re all done with the root window, you’ll want to type the exit command to get out of this window since you’re still the root user in it.

If you had the /home directory structure installed on some other disk and it failed physically, then having /root somewhere else keeps you from loosing the ability to at least boot the system as a super user for recovery purposes. Most distributions make it so that the different normal users’ directories are readable to one another. They’re each given 755 Unix permissions. The /root directory is special because it has 700 permissions, which means only the root super user can ever read from it.

When you see the ~ symbol, this is just a stand-in that the shell uses to represent the user’s home directory irrespective of where it is, so as long as you got similar or identical output to above you have no error to correct. You may sometimes come across the term tilde, which is the literal name for this symbol and means the same thing.