rainbowbird
11/21/2019 - 6:43 AM

How to become Root user in Ubuntu Command Line using su and sudo

How to become root

To become root user from an unprivileged (normal user account) account when there is no root password set, use this command:

sudo -s

Enter the password of your Ubuntu user when requested.

Only Ubuntu users that are members of the sudo group are able to become root user like this. The user that is created during Ubuntu installation is a member of the sudo group by default.

  • /etc/adduser.conf

Get Temporary root access through the sudo command

Instead of logging in as a root in the command line and getting on to the # (root user) command prompt, you can use the sudo command with your other commands to temporarily become root.

Unlock/lock root account

Most Ubuntu systems have root account locked by default.

You can, however, unlock it by entering the following command as sudo:

$ sudo passwd root

The system will ask you to enter a new UNIX password twice. After that, it will update the root password and the account will be unlocked.

After you are done with performing your root operations, you can lock the root account again by entering the following command:

$ sudo passwd -dl root

How to change the root password (An alternative approach)?

Only a root user can change his/her own password. Therefore you need to login as root first. Enter the following command to do so:

$ sudo -i

The system will prompt you to enter the current sudo password. Please enter the password and hit Enter.

Now that you are logged in as root, you can change the passwd for the current (root) user by using the passwd command as follows:

$ passwd

Reference

https://vitux.com/how-to-become-root-user-in-ubuntu-command-line-using-su-and-sudo/