This article explains the process of resetting the root password in a CentOS Linux machine in case you have forgotten the root password. “Root” is the superuser of a Linux machine. In order to access the Linux server as a root user, you need to authenticate first. In case you have forgotten root password, you can reset it by logging in to the machine in “single user mode”. Single user mode (run level 1) is an important runlevel in which only the system administrator is using the machine and has only as few system services as possible are running, including logins.
We can go through the following steps for entering the single user mode:
Boot your Linux machine and select the OS when it enters the GRUB. Here, only “CentOS” is available in this Linux machine. Type “e” to edit the entry.
It will display a page similar to the one shown below. Select the second line which specifies “kernel”. Then, type “e” to edit this line.
It will start the grub editor where you can edit the entry. At the end of the line, append the word “single” or character 'S'. Then press “ENTER”.
Then, type “b” to boot the machine. The Linux machine will boot into single user mode and will display a shell prompt. Now, you can reset the root password using the following command:
It will prompt to enter the password. Once you have successfully changed the password, reboot the machine using the “reboot” command.