In this post we will discuss how to reset the root password of a Redhat linux server if you forgot it.
- Reboot the server
- While you are at boot menu press “Up or Down” arrow key to prevent system from booting.
- Select the boot device and press “e” to edit it.(refer Image 1)
- Scroll down the program with arrow key, till you see a line starting with “linux16”. That line will have words “rhgb quiet” .(refer Image 2)
- Now change “rhgb quiet” to init=/bin/bash as in image 3.
- After making the change press “ctrl x” to boot the system.
- Screen will now take you to command prompt without asking for password.
On the command prompt remount root as read-write.
mount -o remount,rw /
Now execute “passwd” command to change the password of root user. (refer image 4)
- Pick strong password else it will throw error of bad password and may not change the password.
- If you are getting error “passwd command not found” ensure that your machine is booted with the disk and not the ISO. Many people working on VMs make this mistake so you are not alone 🙂
- If you are using SElinux you will have to run this extra relabel step before reboot or else you won’t be able to login with the new password.
- Finally reboot the server
Now you should be able to login with new password.
Hope this post is helpful to you. Do let me know if you have any query.