By default, in Ubuntu distribution you can’t login as root user. Although, You could have access to superuser privileges through sudo -i command. Moreover, this is specifically applicable only for the user account you created while installing Ubuntu distribution. However, for other users you create at a later stage, it will throw an error – <user-name> is not in the sudoers file. This incident will be reported. Read how to add a user as sudoers here if you have the issue. For the purpose of this article, we would focus only on how to enable or disable root user account access in Ubuntu.
Note: We need to take utmost care while we are logged in as root. If you don’t know what you are doing then it is better to contact your System Administrator for assistance. Furthermore, following operations would require you to have access to superuser privileges.
Enable root user account access
If you simply try to login as root, it won’t let you login.
Therefore, we would utilize the command-line utility passwd. Run the following in terminal, after you login with a user who has sudo access.
sudo passwd root
It would ask you to enter sudo password for the logged-in <user-name>.
Thereafter, it would ask you to enter the password details for root user. Enter the same password twice and you would receive the passwd: password updated successfully message.
Thus, you should be able to login as root in command-prompt.
Disable root user account access
Now, for some reason you would want to disable root user access. In that scenario too, we would use the passwd command-line utility. To disable root user account, run the following in terminal –
sudo passwd -l root
-l option is used to lock the user account followed by <user-name>.
Once you have successfully modified user account access, you would get the message – passwd: password expiry information changed
Note: This won’t disable root user account itself. It just locks the user account rendering it inaccessible. Also, those users who have been locked with the option can’t change their own password any further.
In conclusion, we have discussed how to enable or disable root user account access in Ubuntu distribution.