CentOS 7 / RHEL 7 : Reset / Recover forgotten root password

來源:互聯網
上載者:User

標籤:difference   password   latest   method   linux   

CentOS 7 / RHEL 7 : Reset / Recover forgotten root password

October 11, 2014 by sharad chhetri 4 Comments

In this post we will learn, how to reset / recover forgotten root password on CentOS 7 / RHEL 7 (Red Hat Enterprise Linux 7). On RHEL 5/6 or CentOS 5/6 series , the method of resetting forgotten root password was same. In latest RHEL 7 / CentOS 7 this time we have found some difference in steps to reset the forgotten root password.

650) this.width=650;" src="https://www.cloudways.com/affiliate/accounts/default1/banners/e609b8b4.jpg" title="" width="468" height="60" style="border:0px;height:auto;" />650) this.width=650;" src="http://www.cloudways.com/affiliate/scripts/imp.php?id=28869&a_bid=e609b8b4" width="1" height="1" style="border:0px;height:auto;" />

Earlier, root password were used to recover from runlevel in case the boot loader password is not set.

Reset / Recover forgotten root password on CentOS 7 / RHEL 7

Follow the given below procedure to reset forgotten root password.

Step 1: Reboot or start the system, edit grub2

Restart/start the system and on getting GRUB 2 boot screen, first press ESC key so that screen get stopped. Then press e key for editing.

650) this.width=650;" src="http://i0.wp.com/sharadchhetri.com/wp-content/uploads/2014/10/vbox-1.png?resize=1315%2C742" alt="vbox-1" class="aligncenter size-full wp-image-5551" width="750" height="423" style="border:0px;height:auto;margin:0px auto 24px;" />

Step 2: Initialize the /bin/sh

Now in next screen, scroll down with the help of arrow key and search for any of these two keyword linux16 or linuxefi on UEFI systems.In our case, we have linux16.

Disable rhgb and quiet parameters in order to enable system messages.

In first screenshot you can see, we first scrolldown to line starting with keyword calledlinux16 . Now remove the parameter rhgb and quiet .

650) this.width=650;" src="http://i0.wp.com/sharadchhetri.com/wp-content/uploads/2014/10/root-passwd-2.png?resize=1313%2C746" alt="root-passwd-2" class="aligncenter size-full wp-image-5552" width="750" height="426" style="border:0px;height:auto;margin:0px auto 24px;" />

In second screenshot you can see, we have removed the rhgb and quiet parameter
Add the below given parameter at the end of line, to initialize the sh shell.

init=/bin/sh

Now press CTRL with x keyword to boot the system.

650) this.width=650;" src="http://i0.wp.com/sharadchhetri.com/wp-content/uploads/2014/10/root-password-3.png?resize=1315%2C746" alt="root-password-3" class="aligncenter size-full wp-image-5558" width="750" height="425" style="border:0px;height:auto;margin:0px auto 24px;" />

Step 3: Remount / root partition , reset root password and autorelable

The filesystem will be in read only mode, hence run the below given command so that you can write on filesystem

mount -o remount, rw /

Now reset root password with given below command

passwd root

Reconfirm the root password.

NOTE: In case system is not writable, the passwd tool fails with the following error:
Authentication token manipulation error

Now run the below given command for relabeling the SELINUX

touch /.autorelabel

Now restart the system. You can use any one of the command.

exec /sbin/init

OR

exec /sbin/reboot

650) this.width=650;" src="http://i0.wp.com/sharadchhetri.com/wp-content/uploads/2014/10/vbox-6.png?resize=1320%2C746" alt="vbox-6" class="aligncenter size-full wp-image-5553" width="750" height="424" style="border:0px;height:auto;margin:0px auto 24px;" />

You will see the system is going to reboot and stuck for a short time. Just wait for a few seconds or minute. Keep pay attention that the screen is stopped when SELIUX relabeling info message appeared on screen.
After a few moment, you will see at the bottom of screen some numerical percentage is running. It states about the completion of selinux relabeling in percentage. After completing 100% , the system will be rebooted.

650) this.width=650;" src="http://i2.wp.com/sharadchhetri.com/wp-content/uploads/2014/10/vbox-7.png?resize=1316%2C744" alt="vbox-7" class="aligncenter size-full wp-image-5554" width="750" height="424" style="border:0px;height:auto;margin:0px auto 24px;" />

After successful booting, you can use your new root password for login into system.

650) this.width=650;" src="http://i1.wp.com/sharadchhetri.com/wp-content/uploads/2014/10/vbox-8.png?resize=1317%2C744" alt="vbox-8" class="aligncenter size-full wp-image-5555" width="750" height="424" style="border:0px;height:auto;margin:0px auto 24px;" />


本文出自 “vincent” 部落格,謝絕轉載!

CentOS 7 / RHEL 7 : Reset / Recover forgotten root password

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.