1. Overview

In this tutorial, we’ll explore the concept of the Linux root. We’ll look into the foundational layer of the Linux operating system. The root, symbolized by a forward slash (/), is the starting point of the Linux directory structure. Under the root directory, we’ll cover its significance as the top-level directory.

Next, we’ll discuss the root user, who possesses unrestricted access to the entire system, emphasizing the critical nature of managing root privileges securely. Lastly, we’ll look at root access.

2. Linux root

When we explore the fundamentals of the Linux operating system, we need to understand the Linux root directory and the Linux root user. The root directory serves as the foundation of the filesystem, while the root user holds the highest administrative privileges. These elements are vital for managing and navigating a Linux system effectively.

2.1. Linux root Directory

The root, symbolized by a forward slash (/), is the starting point of the Linux directory hierarchy. As the top-level directory, it’s the parent directory from which all other directories and files branch out in a tree-like manner. This arrangement ensures that all files and directories are accessible through a single, hierarchical path.

For instance, if we need to access a user’s home directory (/home/username), system binaries (/usr/bin), or temporary files (/tmp), we start our path from the root directory followed by the name of the directory we want to access. The consistency simplifies file management and system navigation, making it easier for administrators and users to locate and manipulate files.

Following, when we access the root directory, we see a variety of subdirectories, each serving a specific purpose within the system:

$ ls -a
.   .cache  boot  etc   initrd.img      lib    lib64       media  opt   root  sbin  sys  usr  vmlinuz
..  bin     dev   home  initrd.img.old  lib32  lost+found  mnt    proc  run   srv   tmp  var  vmlinuz.old

For example, the /bin directory contains essential binary executables needed for system boot and operation, such as basic commands like ls and cp. Similarly, the /etc directory holds configuration files crucial for system administration, and the /lib directory houses essential shared libraries and kernel modules.

The root directory and its contents make up the root filesystem (rootfs). The root filesystem contains the most important files required for system operation and is mounted at boot time. This includes the kernel, essential system libraries, and utilities. rootfs must be available and mounted for the system to function correctly.

2.2. Linux root User

When we talk about the root user, we’re referring to the most powerful user account on a Linux system. The root user, often called root, has unrestricted access to all commands, files, and resources on the system. This superuser status makes the root account integral to system administration but also necessitates careful handling due to its vast privileges.

Unlike regular users, the root user can read, write, and execute any file, regardless of its permissions. This means the root can modify system configurations, install or remove software, manage users, and access restricted files. For example, we need root privileges for commands such as useradd, apt-get install, and systemctl restart to ensure that critical system changes are made.

However, the root user’s unrestricted access also poses significant security risks. If compromised, an attacker could potentially control the entire system, access sensitive data, and disrupt services. Therefore, it’s crucial to follow best practices for root account management. One such practice is disabling direct root login, especially over network services like SSH.

Instead, we need to configure sudo for administrative tasks, ensuring that root access is logged and accountable. For example, editing the SSH configuration file (/etc/ssh/sshd_config) to set PermitRootLogin no helps mitigate remote attacks on the root account. Another important practice is setting strong, unique passwords for the root user and limiting the number of users who can execute sudo commands.

Additionally, we need to set up multi-factor authentication (MFA) to add an extra layer of security.

3. root Access

In Linux, the root user, also known as the superuser, possesses unrestricted access to all commands, files, and resources on the system. This user has full system access, which is essential for administrative tasks. To perform administrator actions, a user must have permission to do the tasks of a superuser. As a normal/restricted user, we can execute commands with root privileges through commands like sudo and su.

To run a command that requires root permission, we need to prefix the keyword sudo before the said command. For instance, running apt install curl throws a permission denied error while when we prefix sudo, it installs successfully:

$ apt install curl
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
$ sudo apt install curl
Reading package lists... Done

On the other hand,  we can use the su command to switch the normal user to a root user’s account. Upon executing su to root’s account, we are prompted for the root password. Once authenticated, we’ll assume the root user’s identity. This approach grants continuous root access until we exit the session, making it more suitable for tasks requiring multiple root-level commands:

$ sudo su 
[sudo] password for nester: 
# whoami 
root

We need to note that, due to the inherent security risks, it’s important to manage the root account carefully. We need to follow best practices to protect our systems from potential threats. In most Linux distributions, the root account is created during installation. However, in some systems like Ubuntu, the root account is disabled.

Alternatively, we can add a normal user to the sudoers file to allow the user to perform administrative tasks without granting them full-time root access. We can achieve this through:

$ sudo visudo 

And in the editor that appears, add the following line:

<username> ALL=(ALL:ALL) ALL

where is the user we want to add.

4. Conclusion

In this tutorial, we’ve looked at Linux root. We’ve discussed the Linux root directory and the Linux root user. The root directory forms the root filesystem which contains critical files and directories necessary for system operation.

Additionally, we looked at the root user account. Where we mentioned that a root account is a superuser and it has access to all system resources and files. Lastly, we mentioned that we should be careful while using the root user account since wrong configurations can damage our system.