There are times when we forget the root password for one reason or another, so it would be impossible for us to access our system. In this article we will see the steps to follow to reset the root password on CentOS 7 / RHEL .
Steps to reset root password :
Step 1 : Boot Up your system and on the Grub2 boot Menu screen, Press e on the Keyboard :
Step 2 : at the end of the linux16 line, add the following line : rd.break
rd.break breaks the boot process before initramfs passes control to systemd.
Then press Ctrl-x to reboot :
Step 3 : Mount the file system as Read/write
The mount point /sysroot is in ro (read only) you must put it in rw (read write) with the command below :
switch_root:/# mount -o remount,rw /sysroot/
/sysroot is now mounted in rw
Step 4: change root
Change the root directory with chroot :
switch_root:/# chroot sysroot
Step 5 : change the root password
sh-4.2# passwd
Step 6 : Set SELinux relabeling on next boot
sh-4.2# touch /.autorelabel
Step 7 : Exit the chroot mode
Type the command exit to exit chroot mode
sh-4.2# exite switch_root:/# logout
To read this article in French click here.
7zip: 9 Commandes utiles de les plus utilisés
Mis en place d’un cluster kubernetes avec kubeadm
Comment installer Splunk sur CentOS
Comment installer Docker sur Rocky Linux 9
Fail2Ban : How to protect Linux services