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!
sudo
. – Keith Thompson Jun 24 '12 at 03:26sudo
requires your password, not the root password. Ubuntu is designed to work without a root password. See https://help.ubuntu.com/community/RootSudo – Keith Thompson Jun 24 '12 at 15:24
– cheshirekow Jun 21 '17 at 22:29Welcome to emergency mode! Give root password for maintenance (or press Control-D to continue):
/etc/shadow
, I see that my system doesn't have a root password, and I was never prompted to create one when I set up the system. I guess if I ever get that "Give root password for maintenance
" prompt I'll just have to press Control-D. (I haven't looked into systemd.) – Keith Thompson Jun 21 '17 at 22:47sudo -i
or equivalentlysudo --login
, which doesn't require a root password. (But see the above comments regarding systemd, which I still haven't looked into.) – Keith Thompson Aug 03 '17 at 23:13