How to reset a root password in Rocky Linux

Categories

How to reset a root password in Rocky Linux

You are here:

Have you forgotten your Rocky Linux root password? This step-by-step guide will assist you on howto reset your Rocky Linux root password.

 

Reboot your server and access grub

Firstly, you need to access the Grub boot editing interface, this is done by restarting your server and pushing the “e” key when the grub menu shows.

 

Edit grub to boot your server to emergency mode

Edit the grub boot configuration by using the arrow keys. After the /swap on the second line will need to add the following text as shown in the screenshot below.

rd.break enforcing=0

Press control and X to initiate the booting process and it will start the Emergency mode scripting shell

 

Mount your filesystem

By default, the sysroot filesystem is read only, therefore we will need to give read and write access to the sysroot filesystem. To this will once your server has booted into emergency mode enter the following:

 mount -o remount,rw /sysroot

Next will need to get access to the file of the sysroot in a confined environment to do this will need to use the following command:

chroot /sysroot

 

Enter your new password

Now we can change the root password on our system using the command:

passwd root

A prompt will come up allowing you to change the password and confirm the password.

Now after changing the password you will need to exit from shell and put the sysroot file system back into read-only and resart the server this is done by:

exit
mount -o remount,ro /sysroot
shutdown -r now

 

Ligin with your new password and tidy up

After the server has been rebooted and the login prompt is showing enter your new password from the previous steps to login to the server.  It is recommended to clean/etc/shadow where the systems store the password, this can be done by running the following commands:

restorecon /etc/shadow

To enable policies of SELinux, run the following:

setenforce 1

 

 

 

 

 

Table of Contents