How to reset the forgotten root user account password in Centos/rhel 7

Source: Internet
Author: User

Have you ever come across a situation where you can't remember the user account password on a Linux system? It's even worse if you forget the root user password. You cannot perform any changes to the entire system. If you forget the user password, it is easy to use the root account to reset the password.

But what if you forget the root account password? You cannot use a user account to reset the root account password because the user account is usually not authorized to perform this task.

Reset forgotten root user account passwords in CentOS 7 and Rhel 7

In case you encounter this situation, this guide article can help you get rid of such dilemmas. This article describes how to reset the Rhel 7 and CentOS 7 root account passwords.

Early this morning, I opened the Rhel 7 Linux server and found it locked. It's not like I screwed up. The password changed the night before, that is, the password is indeed forgotten.

Forgotten Root account password

So, what am I supposed to do now? Should I log on with a user account and try to change the root account password?

Only the root user can set a password

Unfortunately, the message I saw was "only root can specify a user name" ("The root account can only specify the username"), and I lost control of the root account. So I'm going to boot into single user mode. To do this, restart the server; Once you see the following screen, press "E" on your keyboard (for editing).

Press "E" to enter the edit boot menu

After you press the "E" on the keyboard, you will see a lot of text, which will be shortened according to the screen size.

Grub Configuration

Search for the text "RHGB quiet" and replace it with "init=/bin/bash" without quotation marks.

Enable Shell

Once you have finished editing, press the "ctrl+x" key combination and it will start to boot with the specified parameters. You will get bash prompt.

Boot system

Now, run the following command on a single user mode to check the status of the root partition.

# Mount | grep root

Check the root partition mount status

You may notice that the root partition is reported as "Ro" (read-only). We need to have read and write access to the root partition to change the root account password.

# Mount-o REMOUNT,RW/

Also check again and see if the root assignment is mounted in read-write permission mode.

# Mount | grep root

Set permissions on the root partition

Now you can change the root account password, just type the passwd command. But it's not over yet. We need to re-tag the selinux context. If we skip the step of re-tagging the entire selinux context, we can use the using password to log in.

# passwd root[Enter new password [re-enter new password]
# Touch/.autorelabel

Reset Root account password

Reboot, log into the root account again and see if everything is OK?

# Exec/sbin/init

Login Root User

Clearly, we have successfully logged into the Rhel 7 system by resetting the root account password from a single user mode.

These steps clearly show how to log in to Rhel 7 and CentOS 7 machines by resetting the root account password from a single user mode.

English: Single User mode:resetting/recovering forgotten Root User account Password in Rhel/centos 7

How to reset the forgotten root user account password in Centos/rhel 7

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.