Sometimes you may need to switch to root user in Linux in order to be able to run certain commands and scripts. Root user has privileges and permissions to access any folder or file, and run any command. However, it does not have account name or user id. Also, many Linux systems, especially cloud ones, do not allow root login. So you have to login as non-root user first, and then switch to root user to execute privileged commands & scripts. In this article, we will look at how to become root user in Linux.
How to Become Root User in Linux
There are several ways to become root user in Linux. Any privileged command needs to be run as superuser or root account.
1. Using sudo -i
If you are logged in as non-root user, then open terminal and enter ‘sudo -i’ command to switch to root user. If you do not have sudo access already, you will be asked for password. Else you will not be asked for password, and will be directly switched to root user.
ubuntu~$ sudo -i [sudo] password for ubuntu: root~$
2. Using sudo -s
You can alternatively log in as non-root user and use sudo -s command to switch to root user. In most systems, root login is not allowed so you will need to use this approach.
ubuntu~$ sudo -s root~$
3. Using sudo su –
su is the command to switch user in Linux. If you issue su – command then it will switch to root user.
ubuntu~$ sudo su - root~#
4. Using su – root
You can also run su command with – root option to switch to root user.
ubuntu~$ su - root root~#
In this article, we have looked at 4 different ways to switch to root user in Linux. You can run these commands on almost every Linux distribution since they are available universally.