How to become a ‘root user’ in Linux?

root user is a privileged user in Linux, which is similar to an administrator in Windows.

All kind of administrative operations can be performed using root user privilege hence it is not advisable to provide root access to anyone who does not have much familiarity with Linux environment, which might cause adverse impact on the system.

Best practice is to disable the root access. UBUNTU basically disables the root access and implies sudo instead of root access.

Normal users can perform administrative tasks with the sudo command, rather depending on the root access privilege to manage the administration activity.

Please refer the below article to configure sudo access in Linux.

Enabling sudo access for a user, will accurately track the user activity and records everything in the message log (/var/log/message).

Click here to discover the effective ways to read log files in Linux.

Refer the below articles to learn more about sudo privilege.

1) Becoming a root User in Linux, using ‘su’ command

su (short form of “substitute or switch user”) command allows us to run commands with the privileges of another user.

su is the simplest way of switching over to root account which requires root password to use the ‘su’ command in Linux.

This ‘su’ access will allow us to retrieve the root user home directory and their shell.

$ sudo su -
Password:
[email protected]:/root# pwd
/root

As when logged in as ‘root’, the command prompt ends with # instead of $.

You may be wondering, why I should use “-” while using ‘su’ command, and what’s the difference.

  • su – : Using “su –” sets the target user environment with HOME, SHELL, USER, LOGNAME and PATH.
  • su : Using “su” preserves the current user environment.

2) Becoming a root User in Linux, using the “sudo -i” command

sudo (short form of ‘super user do’) command allows us to temporarily run other commands as root. This is the best way to execute root commands since it records everything which is being performed with the sudo command.

Users does not require the root password to gain root access. Instead, users will enter their own password to avail temporary root access.

$ sudo -i
[email protected]:/root# pwd
/root

Once switching over to root using the above command, an interactive root shell will open and directs to the root home directory (/root).

Alternatively, every command can be run directly from the user session, just by adding ‘sudo’ before each command that runs.

$ sudo ip a

3) Becoming a root user in Linux, using the “sudo -s” command

sudo -s command provides root access and eventually protects your current environment, including shell-specific settings and the home directory.

$ sudo -s
[email protected]:/home/magesh# pwd
/home/magesh

Conclusion

This article provides an insight while using the ‘su’ and ‘sudo’ command in your Linux environment.

Kindly support us by sharing this article with your friends and colleagues!

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

Your email address will not be published. Required fields are marked *