Home > Article > System Tutorial > How to reset RHEL7 or CentOS7 system password
Introduction | The world of RHEL7 has changed, and so has the way to reset your root password. While the old method of interrupting the boot process (init=/bin/bash) still works, it is no longer recommended. "Systemd" uses "rd.break" to break boot. Let’s take a quick look at the entire process. |
Reset the root password in RHEL7/CentOS7/Scientific Linux 7.
RequireRHEL7 / CentOS7 / Scientific Linux 7
Difficulty levelmedium
guideThe world of RHEL7 has changed, and so has the way to reset your root password. While the old method of interrupting the boot process (init=/bin/bash) still works, it is no longer recommended. "Systemd" uses "rd.break" to break boot. Let’s take a quick look at the entire process.
Boot into minimal modeRestart the system and press e on the kernel list page before the system starts. You will enter edit mode.
Interrupt startup processIn the kernel string - enter rd.break on the line ending with linux 16 /vmlinuz- ect. Then Ctrl X restart. The system boots into the initialized memory disk and is mounted at /sysroot. You do not need to enter a password in this mode.
Remount the file system for reading and writingswitch_root:/# mount -o remount,rw /sysroot/Make /sysroot the root directory
switch_root:/# chroot /sysroot
The command line prompt will change slightly.
Change root passwordsh-4.2# passwdLoad SELinux policy
sh-4.2# load_policy -iSet the context type in /etc/shadow
sh-4.2# chcon -t shadow_t /etc/shadow
Note: You can skip the last two steps by creating the autorelabel
file as follows, but automatically rebuilding the label will take a long time.
sh-4.2# touch /.autorelabel
For this reason, despite it being simpler, it should be considered a "lazy person's choice" rather than a recommendation.
Exit and restartExit and restart and log in with the new root password.
The above is the detailed content of How to reset RHEL7 or CentOS7 system password. For more information, please follow other related articles on the PHP Chinese website!