Home  >  Article  >  System Tutorial  >  How to reset RHEL7 or CentOS7 system password

How to reset RHEL7 or CentOS7 system password

王林
王林forward
2024-01-15 18:39:111030browse
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.

RHEL7 or CentOS7 的系统密码如何重置

introduce Purpose

Reset the root password in RHEL7/CentOS7/Scientific Linux 7.

Require

RHEL7 / CentOS7 / Scientific Linux 7

Difficulty level

medium

guide

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.

Boot into minimal mode

Restart the system and press e on the kernel list page before the system starts. You will enter edit mode.

Interrupt startup process

In 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 writing
switch_root:/# mount -o remount,rw /sysroot/
Make /sysroot the root directory
switch_root:/# chroot /sysroot 

The command line prompt will change slightly.

Change root password
sh-4.2# passwd 
Load SELinux policy
sh-4.2# load_policy -i 
Set 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 restart

Exit 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!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete