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

Get a list of your top 10 most frequently used terminal commands in Linux

I think the commands I use most often are: Choice...

How to configure MySQL on Ubuntu 16.04 server and enable remote connection

background I am learning nodejs recently, and I r...

Example code for using HTML ul and li tags to display images

Copy the following code to the code area of ​​Drea...

Examples of optimistic locking and pessimistic locking in MySQL

The task of concurrency control in a database man...

Application of mapState idea in vuex

Table of contents 1. Map method 2. Application ba...

Tutorial on configuring and using i3 window manager in Linux

In this article, I will show you how to install a...

js development plug-in to achieve tab effect

This article example shares the specific code of ...

Detailed tutorial on configuring nginx for https encrypted access

environment: 1 CentOS Linux release 7.5.1804 (Cor...

Detailed steps to install Hadoop cluster under Linux

Table of contents 1. Create a Hadoop directory in...

Tutorial on installing MySQL 5.7.9 using RPM package under CentOS 7

Recorded MySQL 5.7.9 installation tutorial, share...

Beginners learn some HTML tags (1)

Beginners can learn HTML by understanding some HT...

MySQL multi-table join introductory tutorial

Connections can be used to query, update, and est...

SQL merge operation of query results of tables with different columns

To query two different tables, you need to merge ...