If you need to change your root password but do not know the old one, you will need to drop to a root shell. When you boot into your computer, as soon as the BIOS screen disappears (the screen with your computers logo on it), start tapping the Shift key until the GRUB menu comes up, and if this option does not work, then tap the Esc key. (If it is already configured to come up then this step is not necessary.)
When you see the menu choose the option of the latest kernel (or the one you normally use) and choose the option right below called "recovery mode".
It should look like this:

This will take you to a menu looking something like this:

Next choose the Root option.
Wait and let everything load until you get to a shell. Now comes the fun. Enter the following command:
passwd your-username
Replace your-username
with your actual username.
If you are unsure of your username you can look at the names of the files in your home folder via:
cd /home
Then run:
ls
This will show you the names of users on your computer.
Now type the command I stated above: passwd your-username
. So that if your username is jane, I would type:
passwd jane
Next you will be presented with an option to enter your new unix password. This is where you enter the password. It will ask you to retype the command and then after two successful passwords were entered the password has been changed. Now log back into your system via
reboot
If you are asked for your root password when entering your new password this will usually help:
Alternative Method
If you get asked for the root password when entering single user mode use init=/bin/bash
on the kernel append line which should boot the machine into a bash console where you can get read/write access to your /etc/shadow
file. You can then either run passwd
or edit the shadow file directly to put in an empty string. This allows you to reboot the machine into its normal environment and log in as root leaving the password blank and then run the passwd
program to set the root password. This should really only be done when the machine is detached from any networks.
(Quote taken from Shawn Lee in an article listed below.)
To boot with init=/bin/bash
as suggested, access the GRUB menu at boot time and press e to enter the editor. Move the cursor to the line starting with linux
and then move the cursor to the end of that line. Enter the text
init=/bin/bash
and press F10 to boot. You should land in a root shell in text only mode. The filesystem will be mounted read only. To make the filesystem writable, enter the command
mount -o remount,rw /
You can then run
passwd username
where username
is the name of the user whose password you want to set. When done, you can reboot with the reboot
command.
If you need more information these links can help: