Disable root account in Ubuntu?

I was asked for root credentials to setup my printer in Ubuntu. This seemed to be caused by a bug. And the suggested workaround is to create a root password. Since it is default that no root password is used in Ubuntu, i wonder how i could revert this changes.

Once i have set a password for root, is there a method to disable it again?


According to Ubuntu online help

Ubuntu developers made a conscientious decision to disable the administrative root account by default in all Ubuntu installations. This does not mean that the root account has been deleted or that it may not be accessed. It merely has been given a password which matches no possible encrypted value, therefore may not log in directly by itself.

If you want to enable root account simply give it some password using

sudo passwd

When you enter this command you will be asked for new password. The password you enter will be the password for root account so be careful and choose a strong password.

To disable the root login use

sudo passwd -l root

This will disable the login using root user name i.e your system will be back to previous state.

If you want more information on Ubuntu user management read the official documentation.


sudo usermod -p '!' root

That will set the root account to have an unusable password.

You can also lock the account to stop people logging in.

sudo passwd -l root

Either approach should do what you want. You don't need to do both.