How to reset the root password in CentOS7

How to reset the root password in CentOS7

There are various environmental and configuration issues in the process of moving bricks, and different errors are always encountered every time. A quick search on Google reveals that solutions that work for others may not work for you. The environment where I encountered the problem this time was:

Windows 10 Enterprise 2016 LTS

VMware® Workstation 14 Pro 14.1.0 build-7370693

CentOS Linux release 7.5.1804 (Core)

I forgot the root password of CentOS 7 installed in VMWare, so I had to reset it

1. Start the client

CentOS7重置root

After entering the above interface, press e , and then enter the following interface

CentOS7重置root

2. Modify the startup file

Move the cursor down and find the location of Linux16 and ro

CentOS7重置root

Change ro rw init=/sysroot/bin/sh and press Ctrl + x to restart.

Let me explain here, some tutorials say to change it to rw init=/bin/sh , but I didn’t succeed! After changing rw init=/bin/sh restart the client and the following error message is displayed

CentOS7重置root

It says that my BIOS has crashed the hw-PMU resources and the guest OS has disabled the CPU. Please shut down or reset the virtual machine. So I searched Google for a long time according to this error, and it said that the Windows system did not turn on CPU virtualization, so I restarted the laptop and entered the BIOS

CentOS7重置root

I found that Intel virtualization Technology was turned on. The problem became more and more outrageous. I decided to change it to rw init=/sysroot/bin/sh !

3. Restart

After restarting the client, enter the following interface and execute chroot /sysroot

CentOS7重置root

Run passwd root to change the root user password.

:/# passwd root
Changing password for user root
New password:
Retype new password:
passwd: Authentication token manipulation error

4. Update /etc/shadow

If an error message is displayed saying Authentication token manipulation error , it means that the root password change failed. The correct answer is here. Because there is no /etc/shadow file, as shown in the figure

CentOS7重置root

There are only gshadow and gshadow- . Regenerate the shadow file through pwconv and set the permissions to -rw-r-----

CentOS7重置root

5. Remount the root partition

mount -o remount,rw /

At this time, change the root password and find that it is OK

:/# passwd root
Changing password for user root
New password:
Retype new password:
passwd: all authentication tokens updated successfully 

CentOS7重置root

Restart the client and log in successfully!

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to quickly modify the root password under CentOS8
  • CentOS 7 set grub password and single user login example code
  • How to change the password of mysql5.7.20 under linux CentOS 7.4
  • How to modify the root password of MySQL in CentOS environment
  • Solution to the problem of still having to enter a password after configuring ssh password-free login in centos
  • How to install and modify the initial password of mysql5.7.18 under Centos7.3
  • How to change mysql password under Centos
  • CentOS 7 Forgot Password Solution Process Diagram

<<:  JavaScript code to implement a simple calculator

>>:  What to do if you forget the root password of Mysql5.7 (simple and effective method)

Recommend

Table related arrangement and Javascript operation table, tr, td

Table property settings that work well: Copy code ...

How to remove the dividing line of a web page table

<br />How to remove the dividing lines of a ...

25 Vue Tips You Must Know

Table of contents 1. Limit props to type lists 2....

Several ways of running in the background of Linux (summary)

1. nohup Run the program in a way that ignores th...

How to use Antd's Form component in React to implement form functions

1. Construction components 1. A form must contain...

Vue calls the computer camera to realize the photo function

This article example shares the specific code of ...

Personalized and creative website design examples (30)

Therefore, we made a selection of 30 combinations ...

Basic knowledge of MySQL learning notes

View Database show databases; Create a database c...

Difference between querySelector and getElementById methods in JS

Table of contents 1. Overview 1.1 Usage of queryS...

Implementation of MySQL index-based stress testing

1. Simulate database data 1-1 Create database and...

Open the app on the h5 side in vue (determine whether it is Android or Apple)

1. Development environment vue+vant 2. Computer s...

In-depth explanation of InnoDB locks in MySQL technology

Table of contents Preface 1. What is a lock? 2. L...

Detailed explanation of HTML area tag

The <area> tag defines an area in an image ...

Detailed explanation of three ways to wrap text in el-table header

Table of contents Problem Description Rendering T...

Service management of source package installation under Linux

Table of contents 1. Startup management of source...