5 Best Ways to Become root user or Superuser in Linux (RHEL / CentOS / Ubuntu)

In this tutorial, I will take you through 5 Best ways through which you can become root user or superuser in Linux. If you want to run any privilege command in your Linux Based Servers then you need to have root or superuser access. There are many commands on Linux System which cannot run through any other user apart from root or superuser.

So you always need to switch or change to root user in case you want to run any privileged commands. This is one of the common scenario every Linux Professionals face in their day to day work. root user is like admin user which has complete control of the System. Here we will look into different ways using which you can switch or change your user to root or superuser to run any of the privileged commands.

5 Best Ways to Become root user or Superuser in Linux (RHEL / CentOS / Ubuntu) 1

Ways to Become root user or Superuser in Linux

Also Read: 10 Popular Kill Command Examples in Linux/Unix(How to Kill a Process in Linux)

Method 1: Use ‘sudo -i’ to become root user or superuser in Linux

If you are currently logged in as non-root user then you can use sudo -i command to login as root user as shown below. If the current user does not have sudo access then it will ask for the password as you can see in the below output but if the current user has sudo access then it won’t ask for the password.

On ubuntu based systems by default root user will be blocked so you have to first login as non-root user and then use sudo -i to login as root user. You can check Step by Step: How to Add User to Sudoers to provide sudo access to the User.

test@test-localhost:~$ sudo -i
[sudo] password for test:
root@test-localhost:~#

-i : Run the shell specified by the target user’s password database entry as a login shell. More on sudo command Man Page.

Method 2: Use ‘sudo -s’ to become root user or superuser in Linux

If you are currently logged in as non-root user then you can use sudo -s command to login as root user as shown below. This method are generally used in Linux based Cloud Instances where you need to first login as different user and then switch to root user to run any privileged commands as by default root user will be blocked.

Advertisements
test@test-localhost:~$ sudo -s
root@test-localhost:/home/test#

-s : Run the shell specified by the SHELL environment variable if it is set or the shell specified by the invoking user’s password database entry. More on sudo command Man Page.

Method 3: Use ‘sudo su -‘ to become root user or superuser in Linux

You can also use su(switch user) command with sudo to switch your user. If you are currently logged in as non-root user then you can use sudo su - command to login as root user as specified below. When you see $ on the output prompt then it means current logged in user is non privileged user and when you see # on the output prompt then it means you are currently logged in as root user.

test@test-localhost:~$ sudo su -
root@test-localhost:~#

Method 4: Use ‘su – root’ to become root user or superuser in Linux

Another way through which you can switch your user to root user is by using su - root command as shown below. By now you should be able to differentiate between sudo and su command. sudo is basically used to run privileged command and su is to switch user. Both of the tools can be used effectively to become root user or superuser on Linux based Systems.

[centos@localhost ~]$ su - root
Password:
Last login: Sun Oct 11 12:37:59 EDT 2020 from 192.168.0.101 on pts/0

Method 5: Use ‘su -‘ to become root user or superuser in Linux

If you do not mention the root user with su command and use only su - command then also by default it will switch to root user or superuser as shown below.

[centos@localhost ~]$ su -
Password:
Last login: Sun Oct 11 12:38:42 EDT 2020 on pts/0

 

 

 

 

 

Popular Recommendations:-

7 Easy Steps to Install PHP on RHEL 8/CentOS 8

Easy Steps to Install Java on Ubuntu 20.04

Best Explanation of Wrapper Classes in Java: Autoboxing and Unboxing with Examples

Best Steps to Install Java on RHEL 8/CentOS 8

15 ansible-vault command examples to encrypt and decrypt sensitive data/files on Linux

C# data types with Best Examples (.NET v4.7)

How to Install PHP on RedHat/CentOS 7 with Easy Steps

How to Install Ruby on Ubuntu 18.04 with Easy Steps

Advertisements

Leave a Reply