Hello Everyone, Today we will talk about “How to reset the root password in linux”. This post will make you learn how to change root password in case you remember the root password and another way in which you do not remember the root password.
First let’s start with the case you remember the root password and you want to change it:
We have to run “passwd root” command. passwd command helps in changing the password of the user.
We can run this command by root account means we have to switch to root account first in order to run passwd root command.
Next, We will get the option for typing the new password for root and reconfirm it by “Retype new password“.
This is the first method to change the root password. Now, We will start the process of changing the root password when we do not remember it.
We have to restart our system and go down towards rescue mode and press e to select it on grub menu.
After that we have to search a keyword linux there and after reaching on linux keyword, We have to press end key and start writing “rd.break enforcing=0“. It is used for disabling the selinux.
After writing rd.break enforcing=0, We have to press ctrl+x to start booting.
It will take us to the emergency mode now.
Now, We have to mount the sysroot again to go to system for changing root password. Also, we have to change ro mode to rw mode by “mount -o remount,rw /sysroot/“. In which -o is option and rw is read-write.
Next, We have to make /sysroot as root directory by “chroot /sysroot/“
Next, We have to make a new password for our root account by the same command “passwd root“.
Now, We have to exit from the emergency mode and come to our normal mode by doing exit twice as our root password is changed successfully.
As you know we have disabled selinux at the time of changing the password. We have to restore the selinux permissions in /etc/shadow file for changing the password of root by “restorecon /etc/shadow“.
If we do not restore the selinux permissions then after a single restart our root password won’t work.
Now the final step is to restart the system and check with the root login by using the new password.
You May Like Our Other Posts:
How to install CentOS 9 minimal
You can download CentOS 9 from this link.
FAQ’s on how to reset the password for root.
Q. What is the root password?
A. It is the password for the superuser account (root) in Linux, which has full administrative privileges.
Q. Why would I need to reset the password for root?
A. You might need to reset the root password if you’ve forgotten it or if you’re unable to perform administrative tasks due to a lost password.
Q. Will resetting the root password affect my data?
A. No, resetting the root password does not affect your data. However, always ensure you have backups of important data.
Q. Are there any security implications?
A. Yes, unauthorized access to the root account can compromise your system. Always ensure physical security and restrict access to recovery modes.
Q. Can I reset the password for a non-root user?
A. Yes, you can reset passwords for non-root users in a similar manner, either from the root shell or using passwd username
after gaining root access.
Q. Will I need to update any configuration files after resetting the password?
A. Generally, no configuration files need to be updated after resetting the password for root account. However, if you use applications that store the root password (like databases), you may need to update those settings.
Discover more from Root Learning
Subscribe to get the latest posts sent to your email.
I was searching for it. Thanks Mate