Home > System Tutorial > LINUX > body text

How to reset RHEL7 or CentOS7 system password

王林
Release: 2024-01-15 18:39:11
forward
1042 people have browsed it
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/
Copy after login
Make /sysroot the root directory
switch_root:/# chroot /sysroot 
Copy after login

The command line prompt will change slightly.

Change root password
sh-4.2# passwd 
Copy after login
Load SELinux policy
sh-4.2# load_policy -i 
Copy after login
Set the context type in /etc/shadow
sh-4.2# chcon -t shadow_t /etc/shadow 
Copy after login

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 
Copy after login

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!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template