To change the root password in Linux, you can follow these steps based on your current access level:
If you already know the root password, open the terminal and switch to the root user by typing su -
and entering the existing root password. Once logged in as root, use the passwd
command to set a new password. You will be prompted to enter the new password twice for confirmation. After completing the process, exit the root session for security.
If you don’t know the root password but have sudo
privileges, you can change the root password directly by using the command sudo passwd root
. Enter your user password when prompted, and then set a new root password as required.
For cases where the root password is completely forgotten, you can reset it by booting into recovery mode or single-user mode. Access the GRUB menu during system startup, edit the boot parameters to include init=/bin/bash
, and then boot into a shell environment. From there, remount the filesystem in read/write mode and use the passwd
command to reset the root password. Reboot the system after resetting.
Always use a strong password for root access and limit its use to essential administrative tasks for security purposes.
-
This reply was modified 3 weeks, 2 days ago by Ashiq.
-
This reply was modified 3 weeks, 2 days ago by Ashiq.