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

Detailed explanation of 4 common data sources in Spark SQL

Generic load/write methods Manually specify optio...

How to use a game controller in CocosCreator

Table of contents 1. Scene layout 2. Add a handle...

Workerman writes the example code of mysql connection pool

First of all, you need to understand why you use ...

Some summary of html to pdf conversion cases (multiple pictures recommended)

Due to work requirements, I recently spent some t...

The shortest JS to determine whether it is IE6 (IE writing method)

Commonly used JavaScript code to detect which ver...

How to use MySQL limit and solve the problem of large paging

Preface In daily development, when we use MySQL t...

Docker volume deletion operation

prune To use this command, both the client and da...

Centos7 implements sample code for restoring data based on MySQL logs

Introduction Binlog logs, that is, binary log fil...

How to create a simple column chart using Flex layout in css

The following is a bar chart using Flex layout: H...

Example of how to upload a Docker image to a private repository

The image can be easily pushed directly to the Do...

How to use React forwardRef and what to note

Previously, react.forwardRef could not be applied...

Six important selectors in CSS (remember them in three seconds)

From: https://blog.csdn.net/qq_44761243/article/d...

Ubuntu starts the SSH service remote login operation

ssh-secure shell, provides secure remote login. W...

Nginx proxy forwarding implementation code uploaded by Alibaba Cloud OSS

Preface Because the mini program upload requires ...