There's a difference between "empty" password (or no password - when you get asked for a password you type nothing and hit enter) and a locked account.
The "root" user on Ubuntu systems is locked by default, that means there is no password at all that would match, not even the empty password.
Your command sudo passwd -dl root
is correct:
- The
-d
flag deletes the password, that means it reverts the password to the empty password. You log in by simply hitting Enter without typing anything.
- The
-l
flag locks the account. It adds a "!" character in front of the stored encrypted password hash. This way, no entered password can match any more, because "!" would normally not appear in any hash of the used type. That means it becomes impossible to log in using a root password.
You should use both -d
and -l
(or short -dl
) together because otherwise your current password would still be saved. If someone unlocks the account later and the current password wouldn't have been deleted, that's what the new password would become. If you could not remember the old one then, you would wonder why the root account is still not accessible until you figure out that there could be an old password set and you would have to reset it somehow again.