Set/Reset root Password and Enable Root Login in Ubuntu
|Table of Contents
- Introduction
- Step 1: Boot into Recovery Mode
- Step 2: Remount the File System in Read/Write Mode
- Step 3: Change the Root Password
- Step 4: Enable Root Login
- Conclusion
Introduction
The root user in Ubuntu is the user with administrative privileges, and it is recommended to use this account only when necessary. However, there may be situations where you need to reset the root password or enable root login in Ubuntu. In this tutorial, we will show you how to set/reset the root password and enable root login in Ubuntu.Step 1: Boot into Recovery Mode
- Reboot your Ubuntu system.
- When the GRUB menu appears, use the arrow keys to select the “Advanced options for Ubuntu” option and press Enter.
- Select the recovery mode option and press Enter.
Step 2: Remount the File System in Read/Write Mode
Once you are in recovery mode, you need to remount the file system in read/write mode to be able to change the root password. To do this, follow these steps:
- Select the “root – Drop to root shell prompt” option and press Enter.
- Run the following command to remount the file system in read/write mode:
mount -o remount,rw /
Step 3: Change the Root Password
Now that you have remounted the file system in read/write mode, you can change the root password. To do this, follow these steps:
- Run the following command to change the root password:
passwd root
- Enter the new root password and confirm it.
Step 4: Enable Root Login
By default, the root account is disabled in Ubuntu, which means you cannot log in as root. However, you can enable root login by setting a password for the root account. To do this, follow these steps:
- Run the following command to set a password for the root account:
sudo passwd root
- Enter the new root password and confirm it.
- Edit the following file:
sudo nano /etc/ssh/sshd_config
- Find the line that says:
#PermitRootLogin prohibit-password
- Uncomment the line and change it to:
PermitRootLogin yes
- Save the file and exit the editor.
- Restart the ssh service:
sudo service ssh restart
Conclusion
In this tutorial, we have shown you how to set/reset the root password and enable root login in Ubuntu. It is important to note that enabling root login can be a security risk, so it should only be done when necessary. Always use the root account with caution and only when it is absolutely necessary.