Change User To Root In Linux

Linux provides different privileges for different account types. The user is a regular user who has normal user privileges. The root is a specific user account which is the administrator or super admin of the Linux system. A regular user can not accomplish all tasks as it has limited privileges and permissions. In order to accomplish some administrator-level tasks, root privileges are required. There are different ways to change the current user to the root in Linux.

sudo Command

The sudo command is used to run commands for the root or other user. We can simply provide the command we want to run as root to the sudo command. The current user is changed to the root for the specified command and this command is executed as the root user. In the following example, we change the user to root for the fdisk command.

$ sudo fdisk /dev/vda

sudo -i Command

The sudo -i command can be used to run the root user interactive shell by becoming the root user. In the following example, we change the current user to the root user.

$ sudo -i

su Command

Similar to the sudo command the su command is used to run commands with other users’ privileges. The su command is also used to change the user to the root.

$ su

su root Command

As stated previously the su command is used to run commands with other users privileges. We can use the su root in order to change the current user to the root like below.

$ su root

Check If Root User

The whoami command is used to print the current user name. We can use the whoami command in order to check if we are root user right now.

$ whoami

Leave a Comment