Reset the root account password for CentOS/RHEL 7

Source: Internet
Author: User

Reset the root account password for CentOS/RHEL 7

Have you ever encountered this situation: cannot you remember the user account password on Linux? If you forget the root user password, the situation is even worse. You cannot perform any changes for the entire system. If you forget the user password, it is easy to use the root account to reset the password.

But if you forget the root account password, what should you do? You cannot use a user account to reset the root account password, because the user account is generally not authorized to perform such tasks.

In case you encounter such a situation, this Guide Article can help you get rid of such difficulties. This article describes how to reset the root account password under RHEL 7 and CentOS 7.

Early in the morning, I opened the RHEL 7 Linux server and found it locked. Either I screwed up the password I changed the previous night or I forgot it.

Forgotten root Account Password

So how can I be better now? I should log on using a user account. Should I change the root account password?

Only the root user can set the password

Unfortunately, the information I see is "Only root can specify a user name" ("Only root accounts can specify user names"), and I lose control of the root account. So I plan to boot into the single user mode. To this end, restart the server. Once you see the following screen, press "e" on the disk (representing editing ).

Press "e" to enter the editing guide menu.

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

Grub Configuration

Search for the text "rhgb quiet" and change it to "init =/bin/bash" without quotation marks.

Enable Shell

Once the editing is complete, press the ctrl + x key combination to start booting with the specified parameter. You will get a bash prompt.

Boot System

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

# Mount | grep root

Check the root partition mounting status

You may notice that the root partition is reported as "ro" (read-only ). You must have read and write permissions on the root partition to change the password of the root account.

# Mount-o remount, rw/

Check again and again to see if the root allocation is mounted in read/write permission mode.

# Mount | grep root

Set permissions for the root Partition

Now you can change the password of the root account. Just type the passwd command. But this is not complete yet. We need to re-mark The SELinux context. If we skip this step of remarking the entire SELinux context, we can use using password to log on.

# Passwd root

[Enter a new password]

[Re-enter the new password]

# Touch/. autorelabel

Reset the root account password

Restart and log on to the root account again to see if everything is normal?

# Exec/sbin/init

Log on to the root user

Clearly, we have successfully logged on to RHEL 7 by resetting the root account password in single user mode.

The steps above clearly show how to reset the root account password in single user mode and log on to RHEL 7 and CentOS 7 machines.

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.