Friday, Aug 7 2020

Which root?

Let's talk about the ambiguous term root in Linux. Depending on the context, the word root can usually mean one of two things. It can refer to the root filesystem which is esentially the very top of the file and directory tree, or it can refer to the root superuser, the administrator of the OS.

Root as the System Administrator

If you have spent some time administering a Windows NT family server (up to Windows XP), you are probably quite familiar with the concept of a super user. The idea is to have the machine accessible by several users, each one minding their own business and utilizing only their own files. These users abide by a set of permissions that limit their access to specific files and directories. As an example, you don't want the user Hax0rBob to be deleting files that belong to GullableJane against her wishes. You do want Hax0rBob to have some rights as a user, such as checking his mail, writing his programs, and uploading his site files. The notion of having each user obey a granted set of permissions is a fundamental concept in multi-user Operating Systems and the same rules exist in Linux.

To implement a harmonious environment where people can co-exist within a server without interfering with each other's productivity is actually quite simple. Typically, an arbitrary user within the machine is chosen and given the ultimate power to delete, create, move files in addition to grant and revoke rights to other users. This person can then assign a specific set of permissions for each user limiting their access to only the resources they need. This user in Windows environments is called Administrator which is quite long to type. Under UNIX OS's, the user is named root.

The root account should not be used for normal everyday tasks. This means our Sysadmin Joe should perform his daily tasks on the machine as the user 'joe' just like everyone else. Checking his mail and writing his programs should all be done as joe. Joe should only switch to being root if absolutely necessary. It is typically a bad habbit to maximize root usage to avoid any permission problems in addition to potential vulnerabilities and threats (the last thing you want is someone exploiting the system to somehow gain root access to your machine). Until we discuss permissions in more detail, you're gonna have to take my word for it.

Root as the Filesystem Directory

Hopefully you understood the simple concept of the root superuser as described above. You're gonna have to put that knowledge aside for now because we're about to discuss a different meaning of the word root.

Before we get too deep, we need to define a couple of terms to ensure everone is following. The term directory refers to an organizational unit where files and more directories can be kept. Directories can be empty and are usually there to keep the files organized. Without directories, every file in a machine would clumped up in a single location. Good luck trying to find anything. The term filesystem, as the name indicates, is collection of files and directories organized in an imaginary hierarchical tree residing on one or more physical data storage unit. In simple words, it's the layout of a bunch of files and directories in all your hard drives. Consider a directory structure (folder view for Windows users) of a typial Linux filesystem. At the very top, you have the main directory (root directory) symbolized by a slash "/" (backslash in Windows). Within that, any UNIX-like operating system such as Linux will have the same directory structure to some extent. You can be sure to find your etc, bin, usr, lib, tmp, dev, proc, home, boot, sbin, and root inside the vast majority of Linux distributions.

Notice how one of the directories above is named "root". This is the home directory of the root account. This means when the system administrator logs on as root, the first directory they will find themselves in is the directory named root (not the main root of the filesystem!). This is the only instance where you will see both the root filesystem and the root user come together.

The typical notation used to denote any of the directories above is formulated by appending that directory name behind the root symbol "/". So when refering to the etc directory, it can be written as "/etc" meaning "you will find the etc directory by first going to the main root of the filesystem then accessing the directory etc". To take it one step further, let's assume there is a directory inside the "/etc" directory that is named "init.d". To access the init.d directory, you would first go to the very top of the filesystem, the "/" directory, then you would enter the "etc" directory which is the parent directory of our destination init.d. You would end your journey by entering the "init.d" directory. The full symbol for the "init.d" directory in Linux is "/etc/init.d". The first slash always denotes the root directory. The second slash is known as a "separator", its sole purpose is to separate the word "etc" from the word "init.d". The symbol "/etc/init.d" is the directions you take to arrive at init.d. This is more commonly known as a path to a given directory.

Closing Words

By now, we should know the difference between the root in "root filesystem" and the root in "root superuser". They have little to nothing in common. For Windows users, the term "root filesystem" should already be familiar to you, it is typically written as "C:\" where C: is the drive letter and the "\" is our root filesystem. The only difference (aside from the slash pointing the other way) is that in Linux, we do not care about which drive letter anything is because they are all combined together in a single filesystem. Instead of having one root for every drive as in the case for Windows, we have a single root for our entire filesystem and each drive is a different directory within that filesystem. Now tell me that's not an awesome concept...

Article by