Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

3/8/2019 How To Reset Your Forgotten Root Password On CentOS 7 Servers | Liberian Geek

How To Reset Your Forgotten Root


Password On CentOS 7 Servers

Sometimes you forget stu . I do. I forget important passwords for important websites
sometimes. Retrieving your forgotten passwords for most websites is easy, all one has
to do remember few details that were used when signing up for the service to get a
password reset for an account.

The di erence is forgetting a password to a system or device with no easy way to reset
it while locked out. CentOS 7 is one such system. If you forget the root password to your
CentOS 7 machine, it’s almost virtually impossible to reset it while you’re locked out.

This brief tutorial is going to show you a simple trick that you can use to reset your
forgotten root password for CentOS 7 servers. This will de nitely come in handy for
webmasters who are locked out of your CentOS machine and can’t sign on.

This tutorial will only work if you have direct access to the machine or serial terminal
access with boot menu options. You can’t reset the root password if you’re remotely
connected since you need boot menu access.

Enhance your coding experience with this split keyboard that o ers up to 9" of
separation.

To get started, turn on the machine that you’ve forgotten the root password on. For
CentOS 7 devices, you’ll be given 5 seconds at the boot menu to select the operating

https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/ 1/11
3/8/2019 How To Reset Your Forgotten Root Password On CentOS 7 Servers | Liberian Geek

system kernel to boot into.

That 5 seconds is important, because allows for  admins to select di erent kernels or
edit existing kernel parameters before booting.

At the boot menu, press e to edit the existing kernel (Core) as shown below.

Next, scroll down to the list until you see the line underlined below ( ro ) . What we need
to do is change that ro to rw and start into a bash shell. It should look like this rw
init=/sysroot/bin/sh.

https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/ 2/11
3/8/2019 How To Reset Your Forgotten Root Password On CentOS 7 Servers | Liberian Geek

Change the ro line to rw and add init=/sysroot/bin/sh

rw init=/sysroot/bin/sh

https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/ 3/11
3/8/2019 How To Reset Your Forgotten Root Password On CentOS 7 Servers | Liberian Geek

After changing that, press Control + X  or Ctrl + X  on your keyboard to start into single
user mode using the bash shell speci ed above. In this mode, we’re going to change the
root password.

In the single user mode, run the command as shown below

chroot /sysroot

https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/ 4/11
3/8/2019 How To Reset Your Forgotten Root Password On CentOS 7 Servers | Liberian Geek

Finally, run the commands below to change the root password.

https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/ 5/11
3/8/2019 How To Reset Your Forgotten Root Password On CentOS 7 Servers | Liberian Geek

You’ll be prompted to create and con rm a new password.  After creating the password,
run the commands below to update SELinux parameters

touch /.autorelabel

Exit and reboot your system. You should be able to sign on and use the system with the
new password you created. That’s how you change the root password on CentOS 7.

Enjoy!

Protect yourself and your devices with the most trusted internet security software
availabe.

Invest in some screen real estate with a new big screen, backlit monitor availabe in ve
di erent sizes and price points.

Richard W / September 24, 2014 / How-To/Tips, Linux, Security / Centos 7

23 thoughts on “How To Reset Your Forgotten Root


Password On CentOS 7 Servers”

swapnil
https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/ 6/11
3/8/2019 How To Reset Your Forgotten Root Password On CentOS 7 Servers | Liberian Geek

March 10, 2015 at 3:47 AM

Nice :)

Salem
March 26, 2015 at 6:07 AM

Good !!

AndyX
March 28, 2015 at 12:12 PM

Thanks for this! It takes a LONG time for the system to nish rebooting after typing
‘reboot’ — at least in VMWare WS 11 running 2+2 cores with 8GB assigned to the VM. In
fact, I think it rebooted twice before I could log in.
So, you should expect quite a wait, maybe dependent on your virtualizer, memory, etc.
Thanks again!

Tomas
March 23, 2016 at 10:46 AM

Adding the enforcing=0 option enables omitting the time consuming SELinux
relabeling process. I’m nearly certain that’s the issue you’ve hit.

Naeem Khan
April 1, 2015 at 9:50 AM

I forgot both the user and root passwd for my server installed centOS

i do the same but it didn’t worked for me :(

any help..?

https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/ 7/11
3/8/2019 How To Reset Your Forgotten Root Password On CentOS 7 Servers | Liberian Geek

Francisco
April 25, 2015 at 2:31 PM

Thanks a lot!

Anup
May 5, 2015 at 12:50 AM

It worked for me.. thanks for the steps and the screenshots.. greatly appreciated!!

Nugroho Widodo
May 30, 2015 at 4:23 PM

Worked for me thanks

Laura
June 3, 2015 at 6:22 PM

Great Tutorial! Worked smoothly on Production server! Thanks a lot!!

taps
July 20, 2015 at 8:36 AM

You should to run the following command too:

exec /sbin/init

Michael
February 12, 2016 at 4:58 PM

https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/ 8/11
3/8/2019 How To Reset Your Forgotten Root Password On CentOS 7 Servers | Liberian Geek

quick question why should we run the exec /sbin/init command as well ?

Varun
August 8, 2015 at 6:44 AM

Hello,
I forgot the touch /.autorelable step. :( Now linux doesnt load. What can be done? Trying
to load on VM wkstn.

porjo
August 11, 2015 at 10:28 PM

Thanks for the tip. Your screenshot images are https:// URLs which my browser refuses
to load. Any reason why these couldn’t be made http://

Fuller
August 13, 2015 at 10:25 PM

You are my hero! You saved my life! Your tip is very clear and so easy to follow. Thank
you so much!

Ricardo Franco
August 20, 2015 at 11:26 PM

Excellent, very useful

Don
October 21, 2015 at 9:58 PM

Hi,

https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/ 9/11
3/8/2019 How To Reset Your Forgotten Root Password On CentOS 7 Servers | Liberian Geek

when I tried rebooting CentOS 7 after those commands, i only get a black screen.

Any advice?

ZeusAzul
January 5, 2016 at 6:08 PM

Could you resolve this issue????

schnieps
October 26, 2015 at 2:31 PM

It works ne, great!

many thank’s

Ram
October 31, 2015 at 5:16 AM

Thanks dude you are Smart :)…!!


it is very useful to root password recovery…!!!

Lazo
November 6, 2015 at 3:56 AM

It works perfectly for my desktop.


Thank you for this helpful information :)

ernie
January 16, 2016 at 1:46 AM

https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/ 10/11
3/8/2019 How To Reset Your Forgotten Root Password On CentOS 7 Servers | Liberian Geek

Elegant and very helpful. Thanks

suresh
March 5, 2016 at 1:26 AM

very nice

AalBaia3
March 25, 2016 at 10:02 AM

thanx a lot , very helpful and clear

Liberian Geek / Proudly powered by WordPress

Cookies

This website uses cookies to ensure you get the best experience on our website. Learn more.

https://www.liberiangeek.net/2014/09/reset-forgotten-root-password-centos-7-servers/ 11/11

You might also like