"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
How To Reset root Password on CentOS 7
1. How To Reset Root Password on RHEL 7
i | P a g e
Table of Contents
Overview.......................................................................................................................................................1
Applies To......................................................................................................................................................1
Pre-requisites................................................................................................................................................1
Choose Kernel - Core.................................................................................................................................1
Find Kernel Entry – ro ...............................................................................................................................2
Modify Kernel Entry – init.........................................................................................................................2
Change Root – sysroot..............................................................................................................................3
Set – Root Password .................................................................................................................................4
Relebal Filesystem – SELinux ....................................................................................................................4
2. How To Reset Root Password on RHEL 7
1 | P a g e
Overview
If you happen to forgot root password of the server. You have to login to the server with single user and
edit the kernel entry and boot and change the root password.
Applies To
CentOS 7, RHEL 7; Tested on CentOS 7
Pre-requisites
Console Access to the system.
Choose Kernel Entry - Core
In order to reset the root password, you need to reboot the server and choose “Core” kernel entry in the
“boot” menu option.
When the boot menu is shown; choose the kernel entry as below and press key “e” as shown below.
CentOS Linux (3.10.0-229.11.1.el7.x86_64) 7 (Core)
Note: Boot screen will be shown only for 5 seconds.
3. How To Reset Root Password on RHEL 7
2 | P a g e
Find Kernel Entry – ro
In the “Edit Kernel” option, navigate till you find text “ro” after root device mapper.
Modify Kernel Entry – init
Next, you need to modify the kernel entry as below; which will instruct the kernel to start into “sh”.
rw init=/sysroot/bin/sh
After modifying, press “Ctrl + x”, kernel will be instructed to start in single user mode.
4. How To Reset Root Password on RHEL 7
3 | P a g e
Change Root – sysroot
Execute chroot command or interactive shell with special root directory. Run the command as below;
chroot /sysroot
5. How To Reset Root Password on RHEL 7
4 | P a g e
Set – Root Password
Now, After running the “chroot” command; in the shell prompt run the command “passwd” along with
login username “root” as below to set new password for the root user.
After command execution, Enter the new password and re-enter the new password again.
passwd root
Relabel Filesystem – SELinux
At boot time, init.rc checks for the existence of /.autorelabel. If this file exists, SELinux performs a
complete file system relabel (using the /sbin/fixfiles -f -F relabel command), and then
deletes /.autorelabel.
To perform the check run the command and reboot the server; after rebooting you can login into the
server with newly set password.
touch /.autorelabel
reboot