Introduction
Before we begin talking about how to enable and disable root user account on Ubuntu, let's briefly understand – What is root user ?
To perform administrative tasks on Ubuntu, the root user account is used. However, it is generally recommended to use the sudo
command to run privileged commands instead of logging in as the root user directly. This helps maintain security and prevents accidental damage to the system.
In this tutorial, you will enable and disable root user account on Ubuntu. We will also address a few FAQs on how to enable and disable root user account on Ubuntu.
Advantages of Root User
- Complete Control: Root users have unrestricted access to the entire system, allowing them to make any changes, install packages, and modify system files.
- System Configuration: Root users can configure all aspects of the system, including network settings, user management, and security configurations.
- Software Installation: Root users can install and update software packages from official repositories or external sources, granting flexibility in managing the system's software ecosystem.
- Troubleshooting: With root access, users can diagnose and fix system issues, delve into log files, and perform advanced troubleshooting steps.
- Customization: Root users can personalize the system by customizing various settings and options, enabling a tailored computing experience.
Sudo Users
Ubuntu users are encouraged to undertake system administration activities by using the sudo tool to grant administrative capabilities to a regular user.
Authorized users can run programs as another account, usually the root user, using sudo.
Sudo access is allowed to members of the sudo group by default on Ubuntu computers. The sudo group is already a member of the account established by the Ubuntu installer. It's likely that the person you're logged in as has administrator access already.
If you wish to give another user sudo access, simply add them to the sudo group:
usermod -aG sudo username
Run the following command, prefixed with sudo
, to temporarily boost root user privileges:
sudo some-command
You'll be prompted for the user password the first time you use sudo in a session.
You'll need to update the sudoers
file if you wish to run a command with sudo capabilities without entering the password. In order to do so, type visudo
:
sudo visudo
This will launch your favorite command line text editor and open the /etc/sudoers
file. Replace username with your username
in the following line:
username ALL=(ALL) NOPASSWD: ALL
Enable Root User Account on Ubuntu
If you need to enable the root account for some reason, all you have to do is create a password for the root user. The passwd
command on Ubuntu and other Linux distributions can be used to set or update a user account's password.
On Ubuntu, you can only update your own password as a regular user. To change the root password, the user you're logged in as has sudo rights.
Run the following command to enable the root account on Ubuntu:
sudo passwd root
You'll be asked to enter and confirm your new root password, which is:
Output
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
That concludes our discussion. The root account has been enabled successfully. With the new password, you can now log in to your Ubuntu machine as user root.
Disable Root User Account on Ubuntu
Set the root password to expire if you already enabled the root user on Ubuntu and now want to disable it.
Use the following command to disable the root account password:
sudo passwd -l root
FAQs to Enable and Disable Root User Account on Ubuntu
Why is it not recommended to enable the root user account?
Enabling the root account can introduce security risks as it provides unlimited privileges. Utilizing sudo
promotes a safer approach by allowing temporary administrative access.
Can I perform administrative tasks without enabling the root account?
Yes, by using the sudo
command. It grants temporary root privileges to specific commands, maintaining security while performing administrative tasks.
How do I run a command as root using sudo?
Prefix the command with sudo
. For example, sudo apt update
would run the apt update
command with root privileges.
Can I log in directly as the root user on Ubuntu?
By default, Ubuntu disables direct root logins to enhance security. It is recommended to log in as a regular user and escalate privileges when necessary.
How do I revert to the default root account settings?
To revert to the default settings, disable the root account using the command sudo passwd -l root
. This locks the password for the root account, effectively disabling it.
Can I create additional users with root privileges?
Yes, you can create users with administrative privileges by adding them to the sudo
group. They can then use sudo
to execute commands with root privileges
Why should I avoid logging in as root?
Logging in as root can pose security risks. Using sudo
allows executing specific commands with root privileges without compromising the entire system's security.
Conclusion
All you have to do to enable the root user account on Ubuntu is set the root password.
Make sure you use a strong and unique password when creating the password. The most critical part of your account's security is having a strong password. A strong password often consists of at least 16 characters, one uppercase letter, one lowercase letter, one number, and one special character.
If you have any queries, please leave a comment below and we’ll be happy to respond to them.