How to change the root password in Ubuntu?

If you are learning Linux commands, and have installed the Ubuntu on your machin than as   a default user root do not have password. To gain root access you have to type in your own user password. This is the password you set for the first user while installing Ubuntu.
You can switch to root user in Console mode by typing following command:

sudo -s -H

To manually set a password for the root user, type in the following in the shell:
sudo passwd

After that you are asked to type in the new root password twice. Finally, your root user has its own password.