If you have forgotten root user password on your CentOS 6 machine, you can reset the password to new value, without knowing the old one, by booting the machine to single user mode, and resetting the password with passwd command.
Boot to single user mode
During the CentOS boot process, you will be presented with a countdown before CentOS boot process actually begins to load the OS.
Press any key to enter the GNU GRUB menu.
On the GNU GRUB menu highlight the kernel you want to boot, and press ‘e’ key to edit the kernel commands before booting.
Once you have entered the kernel edit mode, find the line beginning with kernel, and highlight it, and press ‘e’ key to edit it.
On the end of the line add the word ‘single’, with white space before ‘single’, and press ENTER to accept the change.
Boot the machine with the edited kernel argument, and you will be logged in as root in single user mode.
Now just issue passwd command, and enter the new password two times, when asked.
Once you have changed the password, reboot the machine, and log to it with your new root password.
If you have forgotten your root user password for your Debian system, you can reset the password to new value, without entering the old one, by going into grub and editing the commands before booting the system.
Edit GRUB before Debian boot
During you machine boot process, you should be presented with GNU GRUB screen with countdown, before the default boot option is activated.
Press any key during the countdown period stop the boot process, and then press e key to edit the commands before booting.
One you have entered into editing mode, find the line starting with linux, followed by /boot/vmlinuz-*, and containing section with root=UUID=.
Line should be towards the end, usually two lines before the final line.
On the end of that line, in most case after ro quiet, add one of the following two: init=/bin/bash or init=/bin/sh, as shown on picture below.
After you have added the init value, press Ctrl+x or F10 key to boot the with the selected options.
Debian should now boot to single user mode, with the root filesystem mounted in read-only mode.
You need to remount it to read-write mode with the following command: mount -n -o remount,rw /.
After that you can use passwd command to change the root password to a new value.
Type passwd to be asked for a new password, and then reenter the new password again, once asked to retype it, and you should then be presented with following message:
passwd: password updated successfully
You can now reboot your machine, and use the new root password on your system.
If this method is not working for your, you can try to boot the system from a LiveCD, and then mount the partition holding your /etc, and edit the shadow file.
In the shadow file, find the line starting with root:, and change the hashed password between “root:” and next “:” to just “!”.
Shadow file should initially look something like this: