Warning: Directly logging in as root is like playing with fire, because one little typo is enough to lose critical data or make your system unbootable. Note that desktop environments will also function incorrectly if you login to them as root.
See these questions for the reasons behind why sudo is preferred and why root-login is disabled by default:
- What are the benefits of sudo over su?
- Why is there no option to login as root?
You may have noticed that you can’t log in as root on Ubuntu, this is because root doesn’t actually have a password set.
Enter the following command:
sudo passwd
You will be prompted for your current user's password, followed by the password you want to set for root. The messages prompted should be similar to the following:
[sudo] password for <username>: <Type your user password and press return>
Type new UNIX password: <Type the root password you want>
Retype new UNIX password: <Retype the root password you chose in the previous prompt>
The following message will appear after that:
passwd: password updated successfully
If the above message showed up on your terminal, you can now enter as root from your current user entering the following command:
su
And you will be prompted for the root password you've set. That's it!