How to grant root privileges in Linux?

In Linux systems, users need to execute tasks as root privileges to access, read, and write files. The root is known as the super user having full rights of administrators to perform various tasks, including executing commands, accessing files, and other administrators tasks.

This guide aims to demonstrate various methods to access root privileges from normal users in Linux systems. The content carried out in this guide is as follows:

Using the “adduser” Command to Add a Root User

The “adduser” command is utilized to add a new user “roger” to the root group with the root privilege. To do so, execute the below script:

$ sudo adduser roger

It requires the “password” through which you access the root privileges.

Additionally, you can add the full name of adding user “Roger” as seen below:

Grant Root Privileges to the User

The “visudo” command assists in modifying the sudoers file in the Nano Editor. To access the root privilege of “roger”, execute the below script:

$ sudo visudo

After executing the command, it navigates to the “/etc/sudoers.tmp” file to perform modifications via Nano Editor:

After scrolling down to the “sudoers.tmp”, copy the script of root privilege and replace it with username “roger” as seen in the below screenshot:

$ roger ALL= (ALL:ALL) ALL

After modifications, save the file via “Ctrl+S” and exit the Nano Editor through the “Ctrl+X”.

Verify User Has Privileges

You can verify that the new user has been switched to the root user with all privileges by executing the below script:

$ su roger

Using “sudo” Command to Grant Root Privileges

In the Linux system, the “sudo” command enables a normal user to execute all operations as the privileges of root. For this, all possible ways to grant the root privileges are mentioned below:

Using the “sudo su –” command

The “sudo su –” command is utilized to switch users whose name is not provided. After executing the command, it navigates to the root user after authentication:

$ sudo su -

Now, you can verify that the normal user has been successfully switched to the root user.

Using “sudo -i”

To change the normal user to the super user, the below script will switch to the root user with all privileges. To do so, execute the below script:

$ sudo -i

After executing the above script, it gives all the authority of root users in the Linux system.

Using “sudo -s”

The “-s” utility is used to execute the script with specific users. But, if the username is not defined in the script, By default, it will switch to the root users:

$ sudo -s

Using “sudo su” Command

An alternative way can also be adapted to switch the privilege of normal to super users by executing the below script:

$ sudo su

The output verifies that the normal user has been switched to the super/root user.

Conclusion

In Linux-based systems, the “sudo” commands are utilized to grant the root privileges after authentication. The “sudo su –”, “sudo -i”, and “sudo – s” commands switch the normal user to the root user with all privileges. It is quite useful for executing commands, accessing files, installing packages, and many more. This guide has explained all possible methods to switch to the root user from the normal user. Furthermore, the methods of adding and deleting users are also demonstrated here.