Friday, November 3, 2023

Centos 7 reset root/ any user lost password / lockout due to cant remember password

1. Need to be in front of the terminal. (Physically if not vm).
2. Reboot the server
3. Press 'e' in the GRUB2 boot screen.

3. bunch of text will come out. We can edit those text. 

  • find the line that load the kernel - begins with 'linux16' in my case.
  • find text "rhgb quiet" , replace it with "rd.break enforcing=0".
  • When done. Press Ctrl X. The system will boot with the parameter edited.
[image text]
4. after boot. terminal prompt appear.

  • remount the root filesystem. "# mount -o remount,rw /sysroot"
  • set the environment to /sysroot "# chroot /sysroot/"
  • change desired password. root/any other user. "# passwd root"
  • when done. remount / to readonly back "# mount -o remount, ro /"
  • Then "# exit". 
  • Then "# exit" againsystem continue to boot.
  • login as root with the newly created password. DO NOT REBOOT YET.
  • SELinux will detect that the password file /etc/shadow has been changed and will restrict access to it).  Instead, you must first restore the SELinux labels on that file:
  • "# restorecon /etc/shadow".
  • Then reboot




Centos 7 reset root/ any user lost password / lockout due to cant remember password

1. Need to be in front of the terminal. (Physically if not vm). 2. Reboot the server 3. Press 'e' in the GRUB2 boot screen. 3. bunch...