Open Source Support Forum

Please or Register to create posts and topics.

How to reset forgotten root password in Linux can't remember your root password! What can you do to reset it?
You can log in with single-user mode and create a new root password.
Here is how to do it...

Instructions for Ubuntu:
Reboot your computer.
When GRUB is presenting the menu list,use the arrows to select the boot entry you want to modify,
and then press e to edit the entry

Search for a line like this:
linux /boot/vmlinuz-4-4.0-22-generic root=UUID=43ad24d3-e\c5b-44ee-a099-a88eb9520989 ro

and change it,to show something like:
linux /boot/vmlinuz-4-4.0-22-generic root=UUID=43ad24d3-e\c5b-44ee-a099-a88eb9520989 rw init=/bin/bash

Now,press control +x or F10 to boot....
You'll be logged in as root.

If all went well you should now see root shell command line and your root partition
should be mounted with read/write flags.
To confirm run:

mount | grep -w /

Now,give passwd and set the new password.
After that,give exec /sbin/init to reboot (shutdown -r won't work)
Now you can login as root with the password you just set!

Instructions for Centos 7
1. Boot the system and when you see the following message
"Press any key to enter the menu", press any key.
(You will see the list of available kernel versions.)

2. use the arrows to select the boot entry you want to modify and then press e to edit the entry

3. Go to the line of Linux 16 and change ro with rw init=/sysroot/bin/sh and hit control +x to boot.

4. Now access the system with this command:

chroot /sysroot

5. Reset the password:

passwd root

6. Update selinux information:

touch /.autorelabel

7. Type exit to exit chroot

8. type reboot -f to reboot your system

If your boot loader is LILO follow these steps:

At LILO boot loader type linux single and press ENTER.

When you get the # prompt you will need to type passwd root to reset password:

passwd root
(again,type twice)

and now,reboot your system,by giving the two commands,one by one: